Last week while teaching my new LINQ and Entity Framework course I got a question asking me to compare EF4 with NHibernate. Not having worked extensively with NHibernate, I wasn’t in a position to address the question. Then yesterday I received an email containing a link to a blog post by Oren Eini (aka Ayende Rahien) doing just such a comparison. Because Ayende comes from the NHibernate camp, I thought it would be interesting to highlight some EF4 capabilities lacking in the current version of NHibernate.
- EF is more than an ORM and supports a streaming model with data readers against the entity model without materializing entities
- EF supports LINQ out of the box (NH doesn’t have it yet)
- EF has a good designer (NH doesn’t)
- EF has much better documentation
- EF has an end-to-end n-tier solution out of the box with Self-Tracking Entities (nothing like that for NH)
- WCF Data Services (Astoria) integrates well with EF
On the other side, NH is a much a more mature ORM product than EF and has better batching capabilities. It is also more extensible, especially as an open-source product. That said, EF also has extensibility points, as evidenced by the EF Extensions project, which enables processing of multiple result sets from stored procedures. EF also allows you to define functions with Entity SQL that are embedded in the entity model, and you can execute queries and commands directly against the database, effectively doing an end-run around EF while mapping the results to entities.
Ayende mentions that NH will add LINQ with version 3.0, as well as better documentation, and I’m confident that EF will fold in features from NH in future releases. The end result will be greater parity between the two products going forward, making the choice even more challenging and determined mostly by philosophical and strategic factors.