Extending the ADO.NET Entity Framework

Last night I gave a presentation on the ADO.NET Entity Framework at the Denver Visual Studio User Group.  It was a great discussion and the questions from the audience helped me tell the story I was trying to tell.  That story is that the Entity Framework is a great data access tool.  It’s extendable and in turn flexible enough to meet the needs of the small point solutions to the enterprise caliber solutions.  What I really like about it is the ability to start simple.  Let’s get a solution up and running and then go back and extend\refactor certain areas to improve the architecture and\or performance.  That’s not saying we shouldn’t do some design work up front, but let’s start by getting a solid solution built and then add on features and improvements in the future. 

Sometimes I think architects focus too much on creating the perfect architecture instead of creating a flexible one.  The solution just needs to work given the current requirements.  Beyond that, it also needs to be flexible so it can change when new requirements and features get defined.  EF lends itself very well to flexibility and extensibility.

The zip file below contains the final solution.  That solution has all the extensions we did to the context as well as the entities in the context.  It also includes a basis for a validation framework.  The validation framework could use some tweeks to make it better.  I leave that to you and your creative minds. 

The zip file also contains a SQL script that will quickly and easily create the sample DB for you.  Both the schema and the data.  All you need to do is change the location of the DB file (.mdf) and the log file (.ldf) in order to run the script.  Once you get the DB created you will have to change the server name in the connection string located in the web.config.  After that everything should run great.  Here is the zip:


I hope that you enjoyed the talk.  If you would like the step by step guide to creating the initial model and setting up the inheritance please visit Rob Bagby’s blog of EF.


  1. Shadow Says:


    Thanks for sharing all of this info regarding EF.

    I do have a question for you. Have a business requirement to allow adding attributes/properties to entities at runtime. I will know the entities and some basic attributes of those entities at design time. But, I may need to create/utilize new ones at run time.

    Are there any patterns/techniques for extending EF to handle this?

    Thanks in advance for any advice you may have.

    My question is similar to this post:

    Similiar to this post: http://stackoverflow.com/questions/476816/entity-framework-add-properties-entities-during-runtim

  2. Ben H Says:

    Hey Shadow, I don't think that EF provides an easy to add properties dynamically at run time. I did come across this (http://www.gamedev.net/community/forums/topic.asp?topic_id=396996) that uses some peices of Reflection to do it. Doesn't look the easiest, but it also doesn't look too bad. Hope this helps.

  3. Shadow Says:

    Thanks for the response, Ben.

    Research has been pointing me towards Reflection in .NET. More so been pointing to new concepts to me like AOP, and languages like Ruby and Python. But I was hoping EF (4) or a third-party product might have tackled this challenge already.

    Looking forward to your SSWUG conference talk this week. Will it be much different than the Denver User Group talk?

  4. Ben H Says:

    Hey Shadow,

    My talk next week is a subset of the one I did in Denver. If you are interested in EF talks then make sure to catch David Yack's talk on the subject as well.

  5. Anonymous Says:

    As a Newbie, I am always searching online for articles that can help me. Thank you

  6. Anonymous Says:

    I think your blog need a new wordpress template. Downalod it from http://templates.wordpressguru.in, The site has nice and unique wordpress templates.