Question

What is NHibernate?

As a followup to my previous question. I am an ASP.NET Programmer, and am wondering how NHibernate would help me get my job done easier and more quickly than it would otherwise. Pretend I know nothing about NHibernate. What is it, and what can it do for me?

 45  25567  45
1 Jan 1970

Solution

 87

NHibernate is an ORM, or Object-Relational Mapper. In the same line as LINQ to SQL, Entity Framework, LLBLGen, and others, ORM tools remove most of the need to write stored procedures to handle common data access (CRUD) for your business objects. ORM tools require that you create (either manually or with a visual designer...depends on the one you choose) a mapping specification that traces which properties of your objects map to which columns of your tables and/or views in your database. When you need to retrieve objects, the ORM tool generates the appropriate SQL for you, and sends it to the database. When the time comes to update your objects, the ORM will not only create the SQL to insert, update, and delete for you...it will also batch those commands so that a single connection and batch of commands are sent to the database and performs the whole thing in a transaction. ORM tools can also improve the efficiency of your queries by allowing you to select entire object graphs in a single go, generating the most efficient SQL for the task.

With ORM tools, you still need to query, however you either with basic methods on the ORM's context or session object, or with a custom query language for that ORM. These days, most ORM's, including NHibernate, also provide LINQ support, allowing you to use standard LINQ syntax to query your object model, which in turn is translated to SQL queries against your database for you.

The benefit of OR mappers is that you centralize almost ALL of your code into your domain, rather than splitting it between domain and stored procs. You lighten the stored procedure load on your database, providing less of a barrier to refactoring your database if the need ever arises, providing greater business agility not only in your domain, but also with your database schema. Since you don't have to write SQL, and especially if you use LINQ, you can often create a more efficient application in less effort with lower long term maintenance costs.

Aside from the inevitable war with your DBA's (if you have them), OR mappers can bring considerable benefits to the table that can reduce implementation effort, improve maintainability, and provide greater business agility.

Hope that answers the question. ;)

2009-06-07

Solution

 0

NHibernate is a ORM (Object-Relational Mapper) tool. It creates an object oriented model based on your database schema.

From https://www.hibernate.org/343.html

NHibernate key features:

  • Natural programming model - NHibernate supports natural OO idiom; inheritance, polymorphism, composition and the .NET collections framework, including generic collections.

  • Native .NET - NHibernate API uses .NET conventions and idioms

  • Support for fine-grained object models - a rich variety of mappings for collections and dependent objects

  • No build-time bytecode enhancement - there's no extra code generation or bytecode processing steps in your build procedure

  • The query options - NHibernate addresses both sides of the problem; not only how to get objects into the database, but also how to get them out again

  • Custom SQL - specify the exact SQL that NHibernate should use to persist your objects. Stored procedures are supported on Microsoft SQL Server.

  • Support for "conversations" - NHibernate supports long-lived persistence contexts, detach/reattach of objects, and takes care of optimistic locking automatically

  • Free/open source - NHibernate is licensed under the LGPL (Lesser GNU Public License)

2009-06-07