Tikal's Solution brief on NHibernate

NHibernate is a mature, open source object-relational mapper (ORM) for the .NET framework.  It handles persisting plain .NET objects to and from an underlying relational database.

NHibernate is a port of Hibernate Core for Java to the .NET Framework.

It's actively developed, fully featured, and used in thousands of successful projects. NHibernate is a popular, fast growing ORM with a helpful community of seasoned developers and used in thousands of commercial and open source projects.

Databases supported by NHibernate: MS SQL Server, Oracle, Microsoft Access, Firebird, PostgreSQL, DB2 UDB, MySQL, SQLite.

NHibernate by default provides stand-alone InProc Level-1 cache out of the box and in easy way possible to integrate Level-2 Distributed Cache implementation like NCache .

 

Why NHibernate?

·         Proven, mature, popular in enterprise environment and well-documented framework

·         Big, active and friendly community

·         Based on widely approved patterns

·         Let to focus attention on the project core - domain model and business logic

·         Flexible and very powerful mapping capabilities

·         Model classes are POCO

·         Powerful querying capabilities – HQL, ICriteria, QueryOver, LINQ

·         Provides an incredible amount of control over all aspects of data-loading behavior

o   write\read batching support

o   multi queries during  single round trip to database

o   future queries

o   collection with lazy

o   batched collection loads to avoid SELECT N+1

o   collection filters and paged collection

·         Caching 

·         Interceptors – easy to implement audition, logging, authorization, validation

·         Tweaking & Flexibility – possible extend  every part of NHibernate

·         Integration & Extensibility - has a lot of extension  projects

 

 

Bellow there is the overview of most interesting and useful projects that extend NHibernate functionality:

 

LINQ provider

Linq for NHibernate allows developers to write queries using LINQ syntax, which are then translated into Criteria Queries that are executed by an NHibernate Session object.

NHibernate Linq support is based on the existing, proven in production, Linq provider in NHibernate Contrib.

LINQ support is integrated in NHibernate 3 via Query<>.

 

Fluent NHibernate

Fluent, XML-less, compile safe, automated, convention-based mappings for NHibernate.

Fluent NHibernate offers an alternative to NHibernate's standard XML mapping files. Rather than writing XML documents (.hbm.xml files), Fluent NHibernate lets you write mappings in strongly typed C# code. This allows for easy refactoring, improved readability and more concise code.

Fluent NHibernate also has several other tools, including:

·         Auto mappings - where mappings are inferred from the design of your entities

·         Persistence specification testing - round-trip testing for your entities, without ever having to write a line of CRUD

·         Full application configuration with Fluent configuration API

·         Database configuration - fluently configure your database in code

 

Castle ActiveRecord

The Castle ActiveRecord project is an implementation of the ActiveRecord pattern for .NET. The ActiveRecord pattern consists on instance properties representing a record in the database, instance methods acting on that specific record and static methods acting on all records.

Castle ActiveRecord is built on top of NHibernate, but its attribute-based mapping free the developer of writing XML for database-to-object mapping, which is needed when using NHibernate directly.

 

NHibernate Search

NHibernate Search is an extension to NHibernate that allows you to utilize Lucene.NET, a high-performance, full-featured text search engine library.

Lucene.NET is port of  Apache Lucene library written in Java. It’s a very powerful technology to bring free text/efficient queries to applications. If suffers several mismatches when dealing with a object domain model like keeping the index up to date, mismatch between the index structure and the domain model, querying mismatch .

NHibernate Search indexes your domain model thanks to a few annotations, takes care of the database / index synchronization and brings you back regular managed objects from free text queries.

Castle ActiveRecord supports integration with NHibernate Search extension – it can manage, index and search ActiveRecord entities.

 

NHibernate Validator (NHibernate Contrib)

NHibernate Validator is a powerful and extensible framework to validate objects during integration with the NHibernate's entity lifecycle.

 


 

 References:

·         NHibernate official site - http://nhforge.org/

·         Fluent NHibernate official site - http://fluentnhibernate.org/

·         Castle project site - http://www.castleproject.org/ActiveRecord/

·         Rahien Ayende blog - http://www.ayende.com/

·         NHibernate Contrib site - http://sourceforge.net/projects/nhcontrib/