NHibernate or Linq?

来源:互联网 发布:mango db mac 编辑:程序博客网 时间:2024/04/29 00:18

First of all I want to help you to choose between NHibernate and Linq. The answer is: it doesn't matter. Both have advantages but few disadvantages. The right choice depends on your feeling. Stick to the option which feels better for you. The reason for that is:



Linq is

  • part of .NET 3.5
  • integrated into Visual Studio
  • allows the usage of Linq and compile time error checking
  • slightly faster in reading, slightly slower in writing than NHibernate

But Linq is also

  • very new
  • generates entity classes for you. The control over your classes is limited. Although you can extend them with partial classes and inheritance. But you don't have that much control as if you're using NHibernate.

NHibernate is

  • mature with a great community in the .NET- and JAVA- world
  • very easy to use
  • database independent
  • lightweight. You can create the entity classes yourself and the mappings
  • slightly faster in saving, slightly slower in reading than Linq
  • HQL queries are supported with Linq (linq to nhibernate)

But NHibernate is also

  • a 3rd party library (which can be +)
  • not integrated into Visual Studio

 

Use ORM!


NHibernate is a mature open source project designed specifically to solve ORM problems. It is an extremely flexible and configurable ORM, and its been battle-proven for many enterprise projects. It is database agnostic, and supports a wide array of different database brands. Like many active open-source projects, it is undergoing constant evolution, which makes good documentation hard to find.


You should defeniteley use a ORM mapper to build your whole application and then, if you feel that certain features lack of performance you should only switch those critical parts of your applciations to stored procs. For instance you can tell NHibernate to call stored procs for certain queries.

That's my personal opinion and I am trying to convince colleagues of using ORM instead of stored procs all the time. It's a tough quest.

原创粉丝点击