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?
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.
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.
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"
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With