Difference between FluentNHibernate and NHibernate's "Mapping by Code"

Ian Vink picture Ian Vink · Nov 20, 2012 · Viewed 13.4k times · Source

I am coming from an Entity Framework and LLBL background for my ORM tools.

I have been asked to build a new system based on NHibernate. I have never done so, so I am coming at it with fresh eyes.

What is the difference between mapping with Fluent NHibernate and "Mapping By Code" in NHibernate? Is there a preference?

Answer

dotjoe picture dotjoe · Nov 20, 2012

Fluent NH

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

vs.

NH's new mapping by code

It is an XML-less mapping solution being an integral part of NHibernate since 3.2, based on ConfORM library. Its API tries to conform to XML naming and structure. There's a strong convention in how the mapping methods are built. Its names are almost always equal to XML elements names.