Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does EF4 compare with NHibernate?

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.

like image 824
Srikar Doddi Avatar asked Jan 31 '11 02:01

Srikar Doddi


People also ask

Is NHibernate better than Entity Framework?

Entity framework requires additional connections to handle databases other than MSSQL, which nHibernate provides. In terms of data loading, SQL generation, custom column types, custom collections, and so on, NHibernate can be modified. However, the entity framework has limited extension points.

Is NHibernate a framework?

NHibernate is a mature, open source object-relational mapper for the . NET framework. It's actively developed, fully featured and used in thousands of successful projects. Easily map regular C# or VB.NET object models designed in Visual Studio.

Is hibernate similar to Entity Framework?

Hibernate is a suite of open source projects around domain models. The flagship project is Hibernate ORM, the Object Relational Mapper; Entity Framework Core: *Lightweight and cross-platform version of the popular Entity Framework *.

Is Dapper better than Entity Framework?

Dapper is literally much faster than Entity Framework Core considering the fact that there are no bells and whistles in Dapper. It is a straight forward Micro ORM that has minimal features as well.


1 Answers

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).
like image 164
anon Avatar answered Sep 19 '22 08:09

anon