8

In the past 2 years since I started writing business applications (before I did either high level front end or very low level systems programming), learned datasets, linq to sql, and now entity framework. The logical thing to look at next seems to be NHibernate.

Reasons I eventually ended up at EF are: (1) it has the best designer support and (2) it is the most supported by Microsoft.

Reasons (these have elements of assumption) I am interested in NHibernate are: (1) it might not get superceded by a totally different thing as quickly as MS churns data access technologies (2) It seems like its either the front running or second to front running tool for what it does and (3) It appears to be stable and tracable back through time quite a bit.

Has anyone published a comparioson of the two? Is one better than the other for certain types of architectures? Or is it just a matter of style and preference?

Aaron Anodide
  • 5,463
  • 5
  • 28
  • 37

2 Answers2

6

At this point I think the main (only?) advantages NH has over EF are some very fine-grained fetching strategies. Instead of lazy-loading OR eager-loading everything, NH gives you some very nice intermediate options.

Having said that, I've never needed that level of control over my data access, and so the simplicity of EF has made the choice an easy one.

Just be aware that the EF designer file that's otherwise so nice to work with can become a nightmare in source control; it doesn't merge well, or at all. Make sure you check it out with an explicit lock anytime you need to change stuff.

Adam Rackis
  • 300
  • 1
  • 7
  • 3
    +1 for the designer thing. I had no good experience with anything related to a designer. – Codism Aug 19 '11 at 21:59
  • don't forget the ability to always work with a DB other than SQLServer. EF generates non-standard sql in some cases. – gbjbaanb Aug 19 '11 at 22:15
  • could you get around the merge problem by putting the designer file into your ignore list and re-generating, because the changes are reflected in the edmx file? – Aaron Anodide Aug 19 '11 at 23:36
  • 1
    @Gabriel, I think the edmx file is what causes the problems. People update the designer, which changes the edmx, then check-in, and if others have done the same, all hell breaks loose. – Adam Rackis Aug 20 '11 at 02:07
  • 5
    If you download the download the (official, Microsoft supported, but not included in .NET 4.0) [EF 4.1](http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-code-first-walkthrough.aspx), you can use Code First and put together your mappings very similarly to FluentNHibernate. Works very well with source control. – Aaronaught Aug 20 '11 at 03:37
3

We're doing a project where the architect chose NHibernate over EF. I wish the choice had gone the other way as a publisher-subscriber requirement was present from the beginning.

If you plan on using sync framework, go with EF, as NHibernate can't cope with the updates (to the columns that specify where the data came from, who changed it and is my copy the latest) that go on behind the scenes.

If you need to replicate data from one database to another (and keep primary keys the same), the session.Replicate function is poorly documented and seems to take longer than a straight copy.

Tangurena
  • 13,294
  • 4
  • 37
  • 65