Entity Framework 4.0: is it worthy now?
I've read a lot complains about Entity Framework in .NET 3.5 SP1, especially about its ineffectively generated SQL. Those complains had prevented me from studying Entity Framew开发者_如何学Goork.
Now Entity Framework 4.0 has come out, which provide a lot of promises. I wonder if it's really a good ORM now, or still not yet? Is it worth to learn and use it in my .NET projects, instead of traditional SQL queries? Have you planned to switch to EF 4.0 yet?
Thanks in advance.
One word: YES!!
Entity Framework 4.0 contains a huge number of additions and improvements, and with the additional templates for POCO's and self-tracking entities, it's definitely ready for prime time now.
If you want to, you can even go so far as to define your entire EF "model" in code - no *.edmx file at all - looks and feels a lot like Fluent NHibernate. You have lots of options with EF4 - and that's a good thing, and a sign that the ADO.NET team really did listen to the community (and work very hard to make those things a lot better now).
In addition to Julie Lerman's book and blog, you should also check out the ADO.NET EF4 team blog - it contains very useful and helpful hints and tips.
This blog post in particular might be of interest to you:
- Improvements to generated SQL in Entity Framework 4
You should really check out Julie Lerman's blog on EF4, she's at once enthusiastic on the product, yet technically correct. As per me, I can tell you that we have already used EF4 in more than a couple production projects with good results :-)
Yes, EFv4 (in .net 4) is in a completely different league than EFv1 (in .net 3.5 SP1).
EFv1 had a lot of limitations and it sometimes generated horrible T-SQL.
The TSQL generated by EFv4 is fine as far as I am concerned; sometimes it has a bit more nesting with subqueries than needed but that is a cosmetic thing that only affects human readability...
If you need ORM and you are limited to .NET Framework then yes EF v4.0 is major upgrade and it is much better than EF v1. But on the other hand it is still only second version and a lot of problems are not solved yet. Also mentioned code first development (no .edmx) is only CTP version which is not ready from production usage. But I believe you can successfully use EF in any kind of project and you will still get some added value in quicker development.
Among limitations you can think about:
- Limited mappings
- Worse experience with EDMX in shared environment
- Bad experience in disconnected scenarios
- No build-in tracing
- Limited extensibility, no hooks
- etc.
EF4 is still missing pretty major components. However, why are you waiting for the perfect product? It's never going to be around. EF4 is quite useful even if it has a few rough edges.
You can use SQL and EF4 side-by-side, so if you happen to run into a scenario where EF4 makes inefficient code or simply doesn't support something, you can always use plain old ADO.NET. The entity framework actually supports constructing entities from DataRow
s, so you can fairly easily plug the results of such a exceptional SQL query back into your normal program flow. Where EF4 shines is in the more normal scenarios where type-safety & intellisense come into play.
Using the entity framework does entail a bit of a learning curve, and the earlier you start, the better. Despite the fact that EF4 isn't quite there yet (in my opinion, anyhow), I'd say: go for it! Use it for a few small corners of your app to get a feel for it.
You can construct an entity connection over an existing (unopened) SqlConnection
which is opened by the EntityConnection
, and using TransactionScope
then permits you to share a single non-distributed transaction between EF and ADO. Taken together, that means you can use small bits of the EF as drop-in replacements for normal ADO queries, transactions and all, as part of the same connection (i.e. without extra overhead from the server's perspective).
No. EF does not support System Conceptual Integrity (neither n-tier architectures), so you'll end up with no architecture at all but a bunch of components with chaotic references, a wrong platform with wrong communication mechanisms.
No for now
Considering the limitations and previous experiance with EF in 3.5 sp1, I would suggest not to consider EF till it stabilises.May be by version 5 , it should I supppose. It would be better if you carry on your design with LinQ to SQL till then.
Happy Programming...
精彩评论