Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 488
Ian Vink Avatar asked Nov 20 '12 19:11

Ian Vink


People also ask

What is difference between NHibernate and fluent NHibernate?

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.


3 Answers

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.

like image 62
dotjoe Avatar answered Oct 19 '22 14:10

dotjoe


Some of it is preference, some of it is existing codebase. There was a time when NHibernate did not have any built in non-XML mapping options. There were a few solutions out there to fix this - e.g. confORM, Fluent NHibernate, and others I'm probably not aware of.

As of 3.2 I believe (perhaps 3.0) NHibernate now has "Mapping by Code". The advantage to this over Fluent NHibernate is that it doesn't require an additional library, and it is supported by the same team as NHibernate. On the other hand, Fluent NHibernate is a bit more mature (From what I've heard) and can support a broader set of mapping functions.

I also mentioned "existing codebase". Obviously, if you have a project that is already mapped with Fluent NHibernate, it would be best to continue on with it. If you're starting fresh, perhaps it is worth a try to use the built-in "Mapping By Code"

like image 43
Origin Avatar answered Oct 19 '22 12:10

Origin


I know this post is old but, for anyone else interested on this matter, I would strongly recommend you to read this blog. It made it pretty clear to me and it even also gives you comparisons between the two approaches.

http://notherdev.blogspot.de/2012/01/nhibernates-mapping-by-code-first.html

like image 3
C3PO Avatar answered Oct 19 '22 14:10

C3PO