35

what is the best way is to use a ORM like Nhibertate or Entity Framework or to do a customer ORM . I will use this ORM for a C# 4.0 project

Jalal
  • 6,594
  • 9
  • 63
  • 100
ma7moud
  • 423
  • 1
  • 4
  • 8

6 Answers6

68

UPDATE 2016

Six years later things are VERY different. NHibernate is all but abandoned, other alternatives were abandoned (eg Subsonic), Entity Framework is perhaps the most common full-featured ORM, and people have been moving to micro ORMs like Dapper for years, to map from queries to objects with a minimum of overhead.

The application scenarios have also changed. Instead of loading and caching one big object graph at the expense of memory and performance, Web Services and REST APIs need to service a high number of smaller requests. This means that a full ORM's overhead is no longer acceptable.

This means that patterns and techniques like Active Record, transaction per request etc have become throughput and scalability killing anti-patterns

One of the most important features nowadays is asynchronous execution , to reduce thread and CPU waste due to waits. NHibernate never made this transition.

Original Answer

Define "best": Is it the most mature, the one with more documentation, bigger community, more mainstream?

NHibernate is more mature, feature rich, with a more advanced community and not likely to be discontinued when MS decides to break compatibility again. Entity Framework is more mainstream and is supported out-of-the-box. You will find more beginner books for EF, more advanced books for NH.

A good option would be to try one of the simpler ORMs like Subsonic and move to more advanced ORMs once you understand how ORMs work, what are the various pitfalls, what SELECT N+1 means [:P]

Just don't try to create your own ORM, there are several dozens out there already! Subsonic, Castle ActiveRecord, NH, EF (of course), LLBLGenPro...

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
  • 1
    Mature, rich and advanced. This language is very descriptive and certainly isn't almost identical to their front page copy, or the copy on every single piece of software's portal...thanks! – Gusdor Oct 19 '15 at 08:06
  • NHibernate is not abandoned--2018 – Konrad Mar 23 '18 at 09:25
  • 1
    @lll yes it was. Notice the *dates* - 2010. Also check the [contributor graph](https://github.com/nhibernate/nhibernate-core/graphs/contributors) in GitHub. Back in 2010-11 NH was really abandoned. The old team, Ayende, Fabio Maulo et al stopped contributing. In 2012 a completely new team took over but it took *5 years* to release something NH 5 with async functionality, a *critical* feature nowadays, esp for web applications. NH 4.0 was essentially a maintenance release. The original code architecture just couldn't handle async – Panagiotis Kanavos Mar 23 '18 at 09:36
  • @PanagiotisKanavos what do you think is better now, EF6, NH or EF Core for a full-blown ORM. – Konrad Mar 23 '18 at 10:03
  • nvm, it's probably opinion-based anway – Konrad Mar 23 '18 at 10:10
  • 1
    @lll nowadays a fundamental requirement is to work well on .NET Core. NH 5 is essentially a *new* ORM that was released only 6 months ago. EF Core 1 was lacking important functionality but used some *very* clever solutions to batching. EF Core 2 added the missing features. Which is better? Too soon to tell *and* depends on the type of application. Better for REST isn't the same as better for Desktop. – Panagiotis Kanavos Mar 23 '18 at 10:17
  • 1
    @lll driver/provider availability and quality is another issue. NH has many *old* providers/dialects that don't provide the latest features. The latest SQL Server is 2012 for example. EF Core has few built-in providers but anyone who creates an ADO.NET provider for eg Postgresql or MySQL adds EF support. That doesn't mean they are always *good*. – Panagiotis Kanavos Mar 23 '18 at 10:22
13

If you can spend some money, have definetely a look at LLBLGEn Pro 3.0

  • full .NET 4.0 support and it's a mature product. Good support it's also useful.
  • wide database support (Oracle,MS Sql,Firebird,MySql,PostgreSQL,Sysbase)
  • nice designer, Model first support and also Database first support

If your budget is thin, then try NHibernate. It's also a mature product,but It has a bigger learning curve. And if you need some support,you can always call Ayende :-)

For smaller projects it's EF 4.0 a good choice.

Martin Fabik
  • 1,084
  • 6
  • 11
8

Most ORMs have their own strengths and weaknesses.

Entity Framework, for example, has the (huge?) advantage of being in the framework itself, but it also is fairly heavy-weight, and a bit more difficult to get up and running (steeper learning curve).

There are some very nice, very easy to use commercial ORMs. I'm currently using Lightspeed in a C# 4 project, and extremely happy with it for this specific scenario.

It really comes down to what you need from the ORM. If you want very quick and easy to setup and use, Lightspeed, subsonic, and others are very nice. If you need full featured, then Entity Framework and NHibernate are good options.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
8

Calling an ORM the best amongst all in General perspective is completely impossible. Each of them are best from different perspectives. You chose the one that best fits to your needs. Linq2Sql was written with performance in mind but it lacks support for other providers,Linq2Sql is very fast. Yet there are others that may not be as fast as Linq2Sql when it comes to dealing with SQL server but they support wide variety of providers. The best idea would be to list down the features you want an ORM to have for your project and select the one that is serves all your needs.` You may ask these questions to chose the right ORM for your project.

  • What database providers you want the ORM to support ? SQL Server,MySQL, Oracle, etc.
  • Do you need model-first or db-first support ?
  • What is my performance criteria [memory, processing] ?
  • Are you going to use it in web-app or a desktop-app ?
  • Do you have distributed clients in your application ?
  • And the list goes on..
Nasreddine
  • 36,610
  • 17
  • 75
  • 94
this. __curious_geek
  • 42,787
  • 22
  • 113
  • 137
2

I use Linq-to-SQL as my main ORM when creating C# applications. I'll eventually move on to Entity Framework, but for now this one is really easy to use and fast.

Sergio Tapia
  • 40,006
  • 76
  • 183
  • 254
1

I would agree with @this. __curious_geek that choosing the right ORM would depend on your requirements.Having worked on both Hibernate and Entity Framework, I feel the latter is more user friendly as it is a GUI based editor. On the feature richness front, NHibernate has an advantage of supporting a lot of database providers. Also customizing NHibernate turned out to be much easier than tweaking the Entity Framework.

Assuming the most tools satisfy your core requirement, I would prefer NHibernate as a vibrant and engaging user community is a big plus for any tool.

Bharath K
  • 2,109
  • 1
  • 14
  • 18