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

+3  A: 

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
+5  A: 

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! Subsoniq, Castle ActiveRecord, NH, EF (of course), LLBLGenPro ...........

Panagiotis Kanavos

Don't forget to visit http://ormbattle.net/ to see how they stack up amongst each other.

Interesting site, but it's run by the DataObjects people so it's not going be completely objective. It's also missing a few of the recommendations here e.g. LLBLGenPro and Castle ActiveRecord. In particular it looks those are the results for EF3.5 - they're holding off updating the table for EF4 (much better) until they've updated their own product (!)
Rup: Yes, but the poster was asking about Nhibertate or Entity Framework, both of which are included, and neither of which the site would be biased toward/against.
OK, sure - I though he was asking about ORMs in general and just cited those as examples. In any case the EF comparison on the site is definitely out-of-date and I think the NHibernate one is too.
Rup: Do you know of any better or more up-to-date .NET ORM comparison site than ormbattle.net?
+3  A: 

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..
this. __curious_geek

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
+3  A: 

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

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