views:

196

answers:

3

I know this has been asked several times and I have read all the posts as well but they all are very old. And considering there have been advancements in versions and releases, I am hoping there might be fresh views.

We are building a new application on ASP.NET MVC and need to finalize on an ORM tool. We have never used ORM before and have pretty much boiled down to two - nHibernate & Entity Framework.

I really need some advice from someone who has used both these tools and can recommend based on experience. There are three points that I am focusing on to finalize -

  1. Performance
  2. Learning Curve
  3. Overall Capability

Your advice will be highly appreciated.

Best Regards,

+1  A: 

EF doesn't have a lot of providers for other databases. EF doesn't have a big community behind it.

NHibernate has community. NHibernate has database providers. NHibernate is a lot more configurable, probably simpler.

I use NHibernate, I've learned it. I checked EF and didn't see anything that would want me to switch.

dmonlord
EF 2 and 4 both have providers for other databases. You're also making statements like "more configurable, probably simpler" when you clearly don't have much experience in EF. -1
Richard Szalay
Sure, ok EF wins, it's better than NHibernate.Sorry Hadi, Richard Szalay has a lot to say about EF, but he's to fancy to make a post about it to help you.
dmonlord
Easy boys :) I agree with you @dmonlord that EF does not have huge community behind it. Although my concerns are with performance, the learning curve (considering we haven't tried it ever) and obviously overall features of the ORM as I do not want to be banging my head saying - oh I should have gone for that.@Richard your recommendations would be highly appreciated :)
hadi
I like EF. That said, EF support for databases other than SQL Server is not free.
Dave Swersky
@dmonlord - No need to get defensive. I actually voted up Tom's answer because he backed his opinion up in a way that made sense. Your answer felt biased and had no citations for your negative opinions, so I down voted it. I usually use NH, but as I don't have enough experience with EF to say whether it's better I didn't put in an answer.
Richard Szalay
+6  A: 

I would use Nhibernate. I would pickup Sharp Architecture as a great framework that wraps NHibernate, ASP.NET MVC and a bunch of other open-source tools into a coherent whole that will give you a solid architectural foundation.

Nhibernate is more mature than EF4. It is well supported by the community. As long as you are willing to get your hands dirty from time to time, you will like it. It's support for LINQ is currently a little weak but it is rapidly getting better. The learning curve is not bad, but things like session management can be a little confusing at first. One of the reasons I like Sharp Architecture is they have all the NHibernate stuff you will need in place and plenty of guidance on how to use it properly in an ASP.NET MVC project.

EF4 has the MS stamp of approval. It is pretty good now but still behind NHibernate. It is a perfectly good choice and you will find lots of docs from MS, MS support and eventually more developers that are familiar with the ins and outs. I should also mention that the Sharp Architecture folks are adding support for EF4 to their overall framework. They will still support NHibernate, but you will be able to use EF4 if you like.

Tom Cabanski
Hey, thanks Tom for you reply. I am very inclined towards the Sharp Arcitecture. But my concern is with several articles over the internet mentioning about performance issues with nHibernate. Now I figured that if you do it right, you can probably achieve a better performance, but then again me and my team are laying our hands for the first time.
hadi
@hadi: NHibernate is not a performance problem. The performance problem is how you use it. For example, if you use lazy loading and loop over a huge result set accessing some property that causes a database I/O for each iteration, performance is poor. I strongly recommend getting a copy of the Nhibernate Profiler from http://nhprof.com/ to check your access patterns and keep performance good.
Tom Cabanski
Thanks mate, I think I would go ahead with nHibernate. Thanks again for your help :)
hadi
A: 

I think it takes more time to learn NHibernate.

EF provides graphical designer, unfortunately NHibernate doesn't have a generic designer. BTW it's not a problem. If you design in domain-driven (DDD) manner, you will design your entities first and you don't care about database structure (as you used to), NHibernate will handle that for you.

EF 4 got closer to NHibernate. I wouldn't start working with EF 3.5, it lacks a lot of features.

If you think NHibernate is too complicated at first sight, you can start with frameworks built on top of NHibernate. ActiveRecords and Sharp Architect are good examples.

AFAIR EF 3.5 supported only SQL Server 2000. It couldn't handle the new data types from SQL Server 2005. I have no information on EF 4 but I suppose it support these improvements.

If you use NHibernate in real word applications, you have to build an infrastructure. E.g. I implemented the Unit of Work and Repository patterns to be able to write tests and create layers in my application. You have to expect the same using EF. Detaching and attaching entities in EF 3.5 was not an easy thing, I had to write tricky extension methods to mark fields dirty and so on. I hope they solved it in EF 4. There is no such problem with NHibernate.

You don't have to write HQL queries in NHibernate, you can use the LINQ provider. I think it's very important. :)

All in all NHibernate is a mature product with good community and commercial support. EF is young but strongly supported by Microsoft. Oh, and EF is a Microsoft-only thing while you can port your NHibernate knowledge to Java as well. It this counts for you.

artur02
NHibernate has a graphical designer.
Michael Maddox
I'm working with SQLite and I don't know about graphical designers supporting it. Please post a link, I would love to use it.I'd like to find a designer that can reverse-engineer a database schema to entity mapping for most of the supported DBs (including SQLite).
artur02