Simple Linq to Sql Enhancements with T4 Templating
I sometimes underestimate the power of the tools that come with visual studio. Usually this is because I’m ignorant of the fact they even exist until I see them used or read about them somewhere else. T4 text generation is no exception. This is a very useful tool that’s built right into Visual Studio 2008 which I discovered while peeking at the new SubSonic 3 code when it came out. (Thanks Conery).
After spending a day drilling into T4 and learning how it works, I have to say that it was definitely time not wasted. I’ve since used it for tons of miscellaneous code generation projects including mostly data layer extensions. And with the help of the data provider specific templates in the SubSonic project, much of the schema extraction code has been provided for us through open source.
I’m a big fan of SubSonic, and I like to push it in all the shops I work with that aren’t already anchored down to another data framework. However, sometimes we still have to fall back to vanilla data layers like Linq to Sql (L2S), Entity Framework (EF), or straight up ADO.Net depending on the shop and its personalities. Having experience using SubSonic opens your eyes to some useful ways you can improve L2S and the others.

