Ayende @ Rahien

It's a girl

NHibernate vs. Entity Framework: Usage

This is in a response to a question on twitter:

image

In general, for applications, I would always use NHibernate. Mostly because I am able to do so much more with it.

For one off utilities and such, where I just need to get the data and I don’t really care how, I would generally just use the EF wizard to generate a model and do something with it. Mostly, it is so I can get the code gen stuff ASAP and have the data working.

For example, the routine to import the data from the Subtext database to the RacconBlog database is using Entity Framework. Mostly because it is easier and it is a one time thing.

I guess that if I was running any of the tools for generating NHibernate model from the database, I would be using it, but honestly, it just doesn’t really matter at that point. I just don’t care for those sort of tools.

Comments

Marc Gravell
11/24/2011 10:28 AM by
Marc Gravell

Unrelated to this post... your "Archive" (right hand bar) seems to be sorting by month number as text, hence Oct/Nov/Dec come between Jan and Feb

Ayende Rahien
11/24/2011 10:35 AM by
Ayende Rahien

Marc, Yes, I know, we are doing some work on RacconBlog now, will be fixed soon

Matthieu MEZIL
11/24/2011 10:55 AM by
Matthieu MEZIL

Thanks for this answer.

"Mostly because I am able to do so much more with it." Do you think about your NHibernate knowledge vs your EF knowledge or do you think about some NHibernate features not supported by EF? If you think about features what are the top ones you think about?

Ayende Rahien
11/24/2011 11:03 AM by
Ayende Rahien

Mathieu, Because EF is really limited in many of its capabilities.

Xing Yang
11/24/2011 11:21 AM by
Xing Yang

Indeed NHibernate has more features and extension points, however sometimes you need to dive into the source code to find out the meaning of an interface method.

Darren Cauthon
11/24/2011 01:07 PM by
Darren Cauthon

I use EF when I'm in the mood to poke out my right eye.

I use NHibernate when I'm in the mood to poke out my left eye.

José F. Romaniello
11/24/2011 01:42 PM by
José F. Romaniello

I wrote a detailed review of EF 4.1 CodeFirst RC vs NHibernate when this version came out. http://joseoncode.com/2011/03/30/entityframework-4-1-rc-code-first-review/

Basically, I won't use EF because is very limited, and for simple things I won't use NHibernate either just ado.net (maybe dapper because it has some nice extension methods).

Jarle Friestad
11/24/2011 02:08 PM by
Jarle Friestad

With nuget there is no execuse for not using NHibernate either. Add package => nhibernate => done

Matthew Shapiro
11/24/2011 02:09 PM by
Matthew Shapiro

My main production app was written with EF code-first. At first I loved it, but the more I use it the more "gotchas" I find. I don't really want to go through the whole thing and waste time replacing it with NHibernate (mostly since I used EF because there was better docs for learning EF4 than NH) but I definitely would use NH over EF for any new projects.

Craig
11/24/2011 10:39 PM by
Craig

Most people who I found prefer EF of NH basically do so because Linq support is 'better'.

Fishy
11/25/2011 10:13 AM by
Fishy

@jose thanks for the review I tried the new EF CodeFirst and after all it is'nt that bad if you want to quickly achieve some simple basic things. For complex projects there is no other solution then NH at the moment and i don't know if the better LINQ support in EF is a real argument against NH since there are a lot of other ways for querying data. Documentation is always an issue and the reference at nhforge is not complete and needs a rework. For instance there is no word about the new ConfORM feature and how to use it. The other issue is support. Jose wrotes: "The experts of nhibernate will answer your question in minutes." In the last couple of months it is really hard to get an answer. I asked some questions with unit tests etc. but without any success. Fabio answered a lot of questions in the past, but since he moved back from the project it is really quite in the forum. But in the end there is alyways ligth and shade :-)

Santos Ray Victorero, II
11/25/2011 10:26 PM by
Santos Ray Victorero, II

Oren,

Did you marry someone from Microsoft? :-)

I just finished a couple of Windows Phone projectsI & I missed NHibernate a lot since had to use Linq to Sql the only choice for Sql CE for WP7.

I kind of agree with Jose; EF is very limited. I will not use that thing for anything serious at all.

ef
11/26/2011 05:51 AM by
ef

EF is just good enough.

Diego Mijelshon
11/26/2011 04:18 PM by
Diego Mijelshon

Here's my comparison, which I did when I started with EF 4.1: http://stackoverflow.com/questions/5101974/net-orm-comparison/5105917#5105917

Now I would add that convention-based mappers for NHibernate (ConfORM, Fluent) are much more mature and flexible.

EF's ONLY selling point is a more complete LINQ provider. Which, BTW, is not so great when you look at some of the horrible SQL it generates. Not to mention you can't pass entities to it (you need to pass the Id).

Jake
11/28/2011 06:24 AM by
Jake

@Diego

You actually missed Entity Frameworks biggest selling point:

Its was made and is publicly endorsed by Microsoft.

Comments have been closed on this topic.