Monday, September 28, 2009


I've been using LINQ to SQL for a while now (even with the lack of support for some SQL Server advanced data types) but I was always wanting for something more. There is great query support with LINQ, but how do I have it do things like automatic rule checking? What happens if I re-vamp some of the fields in a table and want that reflected back in my DBML and entities? How do I make data annotations so that I can apply validation support in the next version of MVC?

Enter PLINQO, a free add-on to LINQ to SQL that adds these things and a lot more. I won't get into all the details of PLINQO as their site explains a lot of it. I want to share my review of it and how it's worked for me so far.

To get PLINQO working, you have to either purchase CodeSmith or download their free trial. The code generation templates for PLINQO come wrapped up in there. Once installed, it's pretty easy to generate a new data project and Dynamic Data project in either C# or VB.NET. From my experience with the product, it seems like the better option for now is to use the C# version. I was getting C# overlap in the VB version (like the static keyword in methods) and there isn't code-behind files to figure out in the C# version.

You really have two choices for code generation here - either let PLINQO build you the projects from scratch or add a CodeSmith project into an existing project. I didn't immediately understand how to do the latter of the two, but it's as easy as adding a new item to a project. Once that's done, right click on the .cst file, manage outputs and add the PLINQO templates to your project.

PLINQO seems to do a pretty good job of making dynamic changes to your DBML file. I did notice that when it generates the entity files, you may have to go back and do some preening. PLINQO extracts out all of the entities in your DBML as separate entity classes in their own files. When I took a couple of entites in the DBML and made their names singular instead of plural, I ended up having two C# entity files, plural and singular. Make sure you delete the entities you're not using anymore (after you copy over your hand generated code, of course).

Another thing I like is the automatic checking of data on submission using data annotations and custom rules. It's nice to be able to put all of this goodness in a data project, surround your CrUD operations with a Try..Catch block and check to see if you have an error. Takes a lot of the validation code out of the presentation layer, which is a good thing.

Overall I'm pretty impressed! The documentation is a little sketchy so far, but hopefully it'll get better in time. The best thing to do if you have questions is to head over to the CodeSmith Community and ask. The folks over there seem more than willing to lend a helping hand.

I would strongly suggest giving PLINQO a try, especially if you're hooked on LINQ to SQL.