When NOT to use the Entity Framework

后端 未结 6 1360
一向
一向 2020-12-22 23:39

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

相关标签:
6条回答
  • 2020-12-23 00:13

    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.

    0 讨论(0)
  • 2020-12-23 00:20

    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.

    0 讨论(0)
  • 2020-12-23 00:25

    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.

    0 讨论(0)
  • 2020-12-23 00:32

    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 article correctly, 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.

    0 讨论(0)
  • 2020-12-23 00:38

    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.

    0 讨论(0)
  • 2020-12-23 00:39

    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.

    0 讨论(0)
提交回复
热议问题