For some days now I’ve been using the ADO.NET Entity Framework on a pet project of mine. My conclusion so far is that it’s useless in most scenarios, and that I’m lucky to not use it on a real business application.
No support for the traditional n-layer architecture with a presentation, business and data-access layer
- It’s not possible to use your own business entities. If you have an existing codebase, then you have to rewrite all the code vs. if you used NHibernate, it’s enough to modify the data-access layer to use NHibernate and map the result to your existing business entities using XML.
- The only supported data source is database. In many applications today, data sources are both databases and services. For the services, you would need to define your own set of business entities and data-access code.
- It is not possible to define the business-entities in a separate assembly. Thus the presentation layer such as a web-application, will need to reference the data-access layer in order to get access to the business entities.
The entity context instance has to be preserved for the entire request in order to allow for select, update and deletion of data. This needs to be taken care of in the business layer. One way of doing this is to add a reference to the System.Web assembly, and then use the request cache available through HttpContext.Current.Items. But you don’t want a dependency on System.Web in your business layer.
As Sean points out in his comment below, a way around this is to detach the object from the original context, attach the object to the new context, then call the extension method defined in Seans comment which will mark all of the properties on the attached object as modified. When SaveChanges() is called, the database will be properly updated. The same goes for deleting an object: detach, attach, DeleteObject(entity) and then finally SaveChanges().- If you want to delete data without using a stored procedure, then you first have to select the data to delete, iterate through each of the returned entities and call DeleteObject(entity), before you call SaveChanges(). Of course, this gives you really bad performance.
No support for calling stored procedures
When you add a stored procedure from the database to your data model, then the stored procedure will only be available through the entity context if it returns any of the model entities. The stored procedure will not be available if it returns nothing or any of the .NET primitive types such as string, int, bool etc.
Problems when updating the model from the database
When you make some database modifications after the model has been created, and you choose to update the model through the designer, then the end result is usually compiler exceptions. In my case, I always end up deleting the model and creating it from scratch, rather than fooling around in the designer generated file to find the bugs.

January 11th, 2009 at 10:25 pm
I think I have to agree with all the points you have made, having been unfortunate enough too see the implications of a project using the entity framework. The particular project in question had to evole into using the entity framework and a custom data access layer and that cannot be good.
January 11th, 2009 at 10:28 pm
nice! you should write more articles.
January 12th, 2009 at 2:33 am
Thanks, very nice overview. I haven’t need to use EF on any project and
these are very good findings for me (and a bit shocking if I speak as Hibernate/NHibernate fan).
Thanks, I and agree with Som.
January 12th, 2009 at 3:40 am
True!
I can’t believe the bugs I’ve been running into, for example, check this crazy designer bug out:
http://www.ytechie.com/2009/01/entity-framework-designer-entityset-naming-bug.html
January 12th, 2009 at 3:53 am
“The entity context instance has to be preserved for the entire request in order to allow for select, update and deletion of data.”
This is not true. I return entities from a WCF service and I have no problem modifying or deleting objects.
You should check out this article: http://msdn.microsoft.com/en-us/magazine/cc700340.aspx. The only thing that I didn’t like about it was the generic implementation of the SetAllModified() method. I modified it with this extension method.
///
/// Sets all the properties of an entity as modified for updating
///
/// Current Entity
/// The current ObjectContext that the Entity is attached to
public static void SetAllModified(this IEntityWithKey entity, ObjectContext context)
{
ObjectStateEntry stateEntry = context.ObjectStateManager.GetObjectStateEntry(entity.EntityKey);
IEnumerable propertyNameList = stateEntry.CurrentValues.DataRecordInfo.FieldMetadata.Select(pn => pn.FieldType.Name);
foreach (string propName in propertyNameList)
{
stateEntry.SetModifiedProperty(propName);
}
}
January 12th, 2009 at 3:53 am
Oops, some of my XML documentation got screwed up in the past, but the code should still be fine.
January 12th, 2009 at 5:00 am
LINQ to SQL has some of the problems of EF (some would argue more or less). However, some pretty large scale applications run on it. For example, earthclassmail.com runs its enterprise mail P.O. Box on it. For Business Intelligence and read-only data…LINQ to SQL has been very nice and simple to use.
I know its supposedly “dead”, but its still a simple ORM and NHiBernate has some nice features that make in a leader in the ORM space. Bottom line its how you use it and if your company is making $$$$ compared to another company who has the most well thought out architecture and best ORM tools but their product sucks this is all a moot point
January 12th, 2009 at 8:35 pm
hmm, i wanted to play with that, however some of those points really scare me away from it.
January 12th, 2009 at 10:30 pm
Bart Czernicki:
I’m sure its possible to create successful products using LINQ to SQL, but at what cost?
1. The entire codebase will be dependent on LINQ to SQL. If it one day doesn’t cover your needs, you either rewrite all the code or add a 2nd set of data-access code (=messy).
2. LINQ to SQL doesn’t handle normalized databases very well, so either denormalize or try to get around it using stored procedures or views.
3. Total dependency on the designer and it’s designer generated code.
4. Finding solutions to all the limitations is really time consuming and frustrating, and a big expense in the long run.
A good ORM should not affect anything in your codebase but the data-access layer.
January 12th, 2009 at 11:25 pm
Sean:
Thanks for the feedback, the post has been updated.
January 12th, 2009 at 11:28 pm
Isn’t it still in beta? I can’t imagine it going to release without support for stored procedures.
January 12th, 2009 at 11:40 pm
Frank:
ADO.NET Entity Framework v1 was released with .NET 3.5 SP1 (aug. 2008) - without proper support for stored procedures.
January 13th, 2009 at 3:05 am
i’m sure it will progressively get better for you as you move along the learning curve.
January 13th, 2009 at 5:06 am
I agree that the Entity Framework isn’t ready for major projects yet. I have used L2S with success though, without any designer use or dependence. Not a tool for every situation though. As for EF at PDC 2008 Tim Mallalieu did a talk about the direction they are heading, and things look promising. Things like better persistence ignorance for your classes, better support for stored procedures, better context management, etc.
http://channel9.msdn.com/pdc2008/TL20/
January 13th, 2009 at 8:48 am
I’ve planned to test it but I haven’t. Thanks for the post.
January 24th, 2009 at 6:31 pm
Check this for SP: http://blogs.microsoft.co.il/blogs/bursteg/archive/2007/12/17/ado-net-entity-framework-tools-stored-procedures.aspx
January 24th, 2009 at 9:15 pm
amrelgarhy:
If you read the comments on the post you referred to, you will see that stored procedures only works if they return an entity type. If they return nothing or any of the .NET primitive types, then for some reason the stored procedures wont be available through the entity context.
February 4th, 2009 at 8:57 pm
I blogged stored proc usage here http://ygizhitsa.spaces.live.com/blog/cns!8A7B4991A271531A!203.entry
March 14th, 2009 at 1:16 pm
I must say, that I can not agree with you in 100%, but it’s just my opinion, which could be very wrong.
p.s. You have an awesome template . Where did you find it?
March 15th, 2009 at 11:25 pm
I’ve tried it on a mayor proyect and:
It makes some things faster to code, other things like Updating are insanely complicated. Bugs are unning free everywhere. Don’t get me started with the data services, it’s almost imposible to delete data with that.
Performance is crummy with big models, and when used with WCF objects can get big when transmitted.
Stored procedure support is a mess.
You will end with at least Two Data Tiers in you project.
PS: Silverligt is awesome.
June 1st, 2009 at 6:53 pm
I gave EF a shot and tried it out during the construction of a fairly large project. I got around some of some of the annoying anti-layered stuff by using a T4 template to auto generate decoupled POCO partial classes and everything was going fine as I was prototyping. However, I had made the assumption that LINQ and EF got along. When I finally got around to turning the crank and executing, I discovered that an absurd number of interface implimenting members of Entity simply resulted in ‘implimentation not supported’ exceptions. I couldn’t even check to see if an Entity collection ‘contains’ an Entity. What is the point of a bunch of of objects representing your data when you can’t even properly query these objects with .NET’s language integrated query? Linq to Entity is a trainwreck. Between EF and Datasets, I’m in favor of voting the ADO.NET team off of the island; these guys make the rest of the .NET teams look bad by way of association.
June 9th, 2009 at 1:35 pm
@Lars-Erik Kindblad:
I disagree with the post you made earlier on the harms of linq to sql.
You said:
“1. The entire codebase will be dependent on LINQ to SQL. If it one day doesn’t cover your needs, you either rewrite all the code or add a 2nd set of data-access code (=messy).”
If you practice proper seperation of concerns and abstract away your data access layer, then the only thing that knows about its details is the data access layer itself. Allowing Data Access code to leak into other layers is bad practice regardless of the method you choose.
“2. LINQ to SQL doesn’t handle normalized databases very well, so either denormalize or try to get around it using stored procedures or views.”
I will give you this one, support _could_ be much better for relationships.
“3. Total dependency on the designer and it’s designer generated code.”
this is just 100% wrong. You can do everything the designer does using attributes an inheritance. I never trust MSFT generated code….
“4. Finding solutions to all the limitations is really time consuming and frustrating, and a big expense in the long run.”
I just gave you solutions to the “limitations” you listed in about 30 seconds. You’re welcome.
“A good ORM should not affect anything in your codebase but the data-access layer.”
I wholeheartedly agree with this statement, and if you code it correctly, then it is easy to isolate Linq To Sql into a data access island that can be swapped in and out of your application at will.