开发者

How does EF4 compare with NHibernate?

Is it any better? I heard the CodeFirst extension but is it ready for primetim开发者_JAVA百科e. Please share your experience with development, any performance overheads, etc.


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).


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:

  • Geography support
  • Optimized SQL generation
  • Product absolutely integrated to Visual Studio
  • Smart database update wizard (synchronization mode)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜