How does EF4 compare with NHibernate?
S

2

6

Is it any better? I heard the CodeFirst extension but is it ready for primetime. Please share your experience with development, any performance overheads, etc.

Sisley answered 31/1, 2011 at 2:46 Comment(1)
ayende.com/blog/archive/2010/01/05/…Waxy
C
6

I think this is a timely question, as I was wondering the exact same thing. I am trying to create a serious e-commerce model and I am trying to keep my POCOs free of persistence concerns as well as trying to stay true to Domain Driven Design. So far, I am very wary, and I am on the fence about whether I should jump ship to NHibernate. The only thing keeping me from doing so is that I assume that Microsoft will improve (and quickly).

Some of the biggest problems so far:

  • Inability to finely control object materialization. EF calls the zero-arg constructor on your POCO, and this is a behavior you cannot change.
  • No enum support. The community has been screaming -- screaming! -- for this, and it hasn't happened. The workarounds are terrible, and pollute your domain model.
  • Weird mapping bugs when trying to control column names and relationships in the database. The main ones I can think of are with compound keys and many-to-many relationships. These can be worked around, and I assume these will be fixed by release time, but they are frustrating nonetheless.
  • Bad SQL. I also do DBA work, and the SQL that EF generates (with or without Code-First) is atrocious.

And this is just the tip of the iceberg: I am only starting to learn EF4 and I'm running into awful roadblocks. As I think of more reasons, I'll add them here. I'm still struggling through it.

(I wonder whether the community will give it another vote of "no confidence.")


More:

  • To add to the "Weird mapping bugs" problem: You cannot control the name of a column if it participates in a self-referencing relationship (for example, if you have a hierarchy). I assume this will be fixed in the final release.
  • Lack of batching, resulting in multiple roundtrips to the database. For example, how do you delete a bunch of items from a collection? Load all entities into memory and delete them one at a time. A smaller gripe is the number of DB hits when inserting into tables that participate in an inheritance relationship.
  • No intelligent way to deal with model changes. EF Code-First loves to completely drop your entire database if it needs to change the schema.
  • Few extensibility points. You can literally count on one hand the number of events that EF4 allows you to subscribe to (and Code-First doesn't provide much more).
Cirque answered 31/1, 2011 at 4:2 Comment(5)
This is very interesting and useful. I hope more SO folks comment before trolls close this thread.Sisley
I would like to hear more, too, as I am /very/ conflicted about committing to EF4 Code-first.Cirque
This is a very good list. All valid points which i have experienced over the past few months. I'd also throw in EF4's lack of GEOGRAPHY data type support (SQL Server), and inability to pass user defined table types (also SQL Server) to stored procs. To combat the former, i had to use triggers, to combat the latter i degaraded to classic ADO.NET.Neiman
In addition to the lack of GEOGRAPHY, I'll add the lack of HIERARCHYID. However, we may be turning this into an EF4/SQL Server wishlist instead of addressing "Is EF4 ready for prime-time?" and the related question "Can EF4 reasonably do what NHibernate does?" (I wish I could start a bounty on this question. I'd gladly donate all of my points for comprehensive opinions.)Cirque
I believe NHibernate also calls the empty arg constructor.Kiki
C
0

As for me - I prefer EF but with some enhancements. Basically EF offers to you the following advantages:

  • Visual Model Editor
  • Database/Model Update wizard (instead of manual XML changes - what is terrible for me)

Also, I'm using 3-rd party commercial tools based on EF and L2S (LinqConnect) that provide for me the following features:

Carew answered 2/2, 2011 at 16:51 Comment(2)
NHibernate also has lots of different designers. You can use it with fluent and automappings with no xmlWaxy
Can you post a link for these designers?Carew

© 2022 - 2024 — McMap. All rights reserved.