views:

2875

answers:

7

I have been playing around with the EF to see what it can handle. Also many articles and posts explain the various scenarios in which the EF can be used, however if miss the "con" side somehow. Now my question is, in what kind of scenarios should I stay away from the Entity Framework ?

If you have some experience in this field, tell me what scenarios don't play well with the EF. Tell me about some downsides you experienced where you whished you would have chosen a different technology.

+7  A: 

One potentially big issue: Entity Framework 1.0 does not support persistence ignorance. This means that your business layer has a dependency on your data access layer.

If your entire application will be hosted in the same process (like a website on IIS) then this is no problem.

If, however, you have a need to remote your entities (to a Silverlight or Windows Mobile client for example), then your entities will not easily serialize across the wire. You will have to create separate data transfer classes to send your entities across the wire, and additional logic to marshal data between your entity classes and the DTOs.

Edit: spelling.

Ryan Michela
Couldn't this be solved that way: Publish entities through a WCF webservice (using ADO.NET Data Services) and consume the entities through a proxy on the client app.. Wouldn't that work?
driAn
Yes, it could (I think!). See my answer!
Duncan
This isn't really correct- you can Detatch entities from their ObjectContext, send them anywhere for processing, then return and Attach them back to the ObjectContext for persistence back to the datastore.
Dave Swersky
+2  A: 

Since EF does not support POCO, it can be difficult to write good unit tests against. That was one of the knocks against it in the Vote Of No Confidence.

If you're wanting to write good tests, EF will raise obstacles. You can work around them, but it is non-trivial.

Bramha Ghosh
+6  A: 

I'm also just at the 'playing around' stage, and although I was worried about the lack of built-in persistence agnosticism, I was sure there would be a "work-around".

In fact, not even a work-around in an n-tier architecture.

WCF + EF

If I've read the following article correctly - http://msdn.microsoft.com/en-us/magazine/cc700340.aspx - then I don't see any problem serializing entities across the wire (using WCF) and also the persistence ignorance isn't a problem.

This is because I'd use PI mainly for unit-testing.

Unit Testing is possible! (i think)

In this system, we could simply use a mock service (by wrapping up the call to the service in ANOTHER interface based class which could be produced from a factory, for example). This would test OUR presenter code (there's no need to unit-test the EF/DAL - that's Microsoft's job!) Of course, integration tests would still be required to achieve full confidence.

If you wanted to write to a separate database, this would be done in the DAL layer, easily achieved via the config file.

My Tuppence Worth

My opinion - make up your own mind about the EF and don't be put off by all the doom and gloom regarding it that's doing the rounds. I'd guess that it's going to be around for a while and MS will iron out the faults in the next year or so. PI is definitely coming in according to Dan Simmons.

EDIT: I've just realised I jumped the gun and like a good politician didn't actually answer the question that was asked. Oops. But I'll leave this in in case anyone else finds it useful.

Duncan
+1 Interesting, thanks..
driAn
"make up your own mind" is the accepted answer to this question? That's very generous.
bzlm
Serialization of entities is currently broken. The IsReference=True decoration on entities prevents serialization to XML or JSON.
Dave Swersky
+3  A: 

Not all data models map nicely to application Entities. If the mapping isn't relatively straightforward, I'd skip the Entity Framework. You'll find yourself doing handstands to make it work without any clear benefit.

Anders Hejlsberg had some interesting comments about object/relational mapping here.

Corbin March
+12  A: 

The Vote of No Confidence lists several missteps and/or missing bits of functionality in the eyes of those who believe they know what features, and their implementations, are proper for ORM/Datamapper frameworks.

If none of those issues are a big deal to you, then I don't see why you shouldn't use it. I have yet to hear that it is a buggy mess that blows up left and right. All cautions against it are philosophical. I happen to agree with the vote of no confidence, but that doesn't mean you should. If you happen to like the way EF works, then go for it. At the same time I'd advise you to at least read the vote of no confidence and try to get a rudimentary understanding of each of the issues in order to make an informed decision.

Outside of that issue and to the heart of your question - You need to keep an eye on the Sql that is being generated so you can make tweaks before a performance problem gets into production. Even if you are using procs on the backend, I'd still look for scenarios where you may be hitting the database too many times and then rework your mappings or fetching scenarios accordingly.

Daniel Auger
This is a newbie EF question - I didn't think you could use sprocs with the EF? My impression was all the SQL, as you say, was auto-generated.
Duncan
It looks like it does, but I have no experience with it. http://msdn.microsoft.com/en-us/library/bb399203.aspx That being said, as with all o/r mappers that have a dynamic SQL engine, I'd only recommend procs for situations where the generated SQL is problematic.
Daniel Auger
@Daniel: +1 for "all cautions against it are philosophical." The Vote of No Confidence reads like PhD dissertation.@Duncan: You can use sprocs with EF. This is handy if you don't like the autogenerated SQL (I haven't had a problem so far but it's possible) or if you want to slowly port an existing sprocs-based app to EF.
Dave Swersky
I believe the only really valid argument in that article was regarding source control contention on the edmx. But this problem is solved with the code first CTP.
Daz Lewis
Daz... Yup. A lot has changed since this question was asked. EF 4 especially with the code first CTP has solved many of the initial concerns.
Daniel Auger
A: 

See this

ArsenMkrt
A: 

Though both SQL CE 3.5 SP1 and Entity Framework 4.0 Beta 1 both support Identity Columns, using these two products together (at least up to the versions listed), Identity Columns are not supported. You will be required to set primary keys on your own.

Other than that, I've been enjoying EF with SQL CE.

Scott