Building a business tier with Nhibernate - Tools

3 minute read

I got a new task: Build Nhibernate based infrastructure, so I decided to check the existing third party tools and my boss gave me a day at home to check them  ;-D .

 I only check tools that:
  • based on existing DB 
  • support oracle 
  • works with NH 3
First tool I got my hands on is NH3SQLLogger

NH3SQLLogger - Nhibernate 3 SQL logger, this is a cool utility that will help you understand what the hell nhibernate is doing , where he is doing his stuff (yes yes a stack trace) and all parameters of queries are also reflected, this is the perfect development time logger.

do not active it on production by default, only if you need to debug prod.

Here is a sample output of this util:

---+ 01/24/2011 10:14:42.57 +---
-- Void Logic.Test.UserRepositoryTest.SaveUser() [File=UserRepositoryTest.cs, Line=86]

INSERT
INTO
"User"
(FirstName, LastName, BirthDate, Gender, PhoneNumber, IsDeleted, Created, LastUpdated, Name, Address_id, FacebookProfile_id)
VALUES
(@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10);

select
last_insert_rowid();

@p0 = 'Chen' [Type: String (0)]
@p1 = 'Kinnrot' [Type: String (0)]
@p2 = 24/01/2011 00:00:00 [Type: DateTime (0)]
@p3 = 'Male' [Type: String (0)]
@p4 = '0578149177' [Type: String (0)]
@p5 = False [Type: Boolean (0)]
@p6 = 01/01/0001 00:00:00 [Type: DateTime (0)]
@p7 = 01/01/0001 00:00:00 [Type: DateTime (0)]
@p8 = 'kinnrot' [Type: String (0)]
@p9 = 1 [Type: Int64 (0)]
@p10 = 1 [Type: Int64 (0)]


NHibernator

  • Allows you to load db configuration by a key in the configuration file, good for application that works with more than one DB.
  • Wraps sessions and transactions for session per HTTP session and session per thread.  
  • No download available only code

NHibernateIt

  •  Allows you to do some basic crud through a generic repository implementation.
  •  Has the same session and transaction encapsulation as in Nhibernator.
Nhibenrate Mapping Generator - Don't know if working(Need to test on a big DB), but should generate mappings and classes from existing db, support MSSQL,Oracle and Postgre SQL.
If you got a DB and don't go fluent, this is probably good solution for a quick start.

Fluent Nhibernate - Framework with fluent interface based mapping and configuration.
Has an auto map feature with a lot of flexible convention over configuration options. One more thing they supply is an easy to use mapping test classes (called PersistenceSpecification ).

* You should consider auto mapping if your DB got name conventions, but you loose the flexibility of the mapping file per entity built in Nhibernate, and non conventional changes will make you write patches (AutoMappingOverride).



Comments