T4 Templates for Entity Framework model-friendly stored procs

While I was in the middle of a flurry of conference prep and travel in April, I got an email pointing me to an interesting blog post by Dave DeWinter who is using T4 Templates to generate entity friendly CUD stored procedures. Why “entity friendly”? Because of a number of rules enforced by the model such as:

If you are using Stored Procs to do function mapping to an entity, you must use all three operations: Insert, Update and Delete.

if you have an association, the foreign key (aka the ID through the navigation property, e.g. Customer.Address.AddressID) must be used in all three (Insert/Update and Delete) stored procedures

If you do function mapping for a single entity in an inheritance hierarchy, you must have mappings for all of the entities except for abstract base types in the hierarchy.

I have been fighting the concept of modifying the database to enable the model (yeah – call me data-centric yet again and call em “she who worries about annoying the DBA” even though all of the DBAs I’ve ever met are pretty easy going)) but something has to give somewhere.

Dave and Ryan Hauert (who has been very active in answering forum questions for EF as of late!) are very pleased with the results of their templates.

Interestingly, at DevConnections, Danny Simmons was talking about providing functionality like this in a future version of Entity Framework.

So I’m going to go check this out, and play with it a little bit and see how it goes.

  Sign up for my newsletter so you don't miss my conference & Pluralsight course announcements!  

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.