Fluent NHibernate

NHibernate is popular in Open-source community, fully featured, mature ORM but the way to config mappings in XML files (.hbm.xml files) is not comfort.

I would prefer to write mappings in strongly typed C# code and enjoy from easy refactoring, improved readability and more concise code.

 

Fluent NHibernate resolves this issue and provides alternative to NHibernate's standard XML mapping files - fluent, XML-less, compile safe.

 

Samples of mappings:

public class CustomerMap : ClassMap<Customer>
{
    public CustomerMap()
    {
        WithTable("Customers");
 
        Id(x => x.Id, "CustomerId");
        Map(x => x.Firstname);
        Map(x => x.Lastname);
        Map(x => x.Email, "EmailAddress");
    }
}
 
Fluently.Configure()
  .Database(MsSqlConfiguration.MsSql2005
    .ConnectionString(c => c
      .FromAppSetting("connectionString"))
    .Cache(c => c
      .UseQueryCache()
      .ProviderClass<HashtableCacheProvider>())
    .ShowSql())
  .Mappings(m => m
    .FluentMappings.AddFromAssemblyOf<Customer>())
  .BuildSessionFactory();

 

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

 

Project official site

http://fluentnhibernate.org/

 

 

 

 

 

Developer