Fluent NHibernate - Fluent mapping for model
Fluent, XML-less, compile safe, automated, convention-based mappings for 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.
Why replace HBM.XML? While the separation of code and XML is nice, it can lead to several undesirable situations.
- Due to XML not being evaluated by the compiler, you can rename properties in your classes that aren't updated in your mappings; in this situation, you wouldn't find out about the breakage until the mappings are parsed at runtime.
- XML is verbose; NHibernate has gradually reduced the mandatory XML elements, but you still can't escape the verbosity of XML.
- Repetitive mappings - NHibernate HBM mappings can become quite verbose if you find yourself specifying the same rules over again. For example if you need to ensure all
string properties mustn't be nullable and should have a length of 1000, and all
ints must have a default value of -1.
How does Fluent NHibernate counter these issues? It does so by moving your mappings into actual code, so they're compiled along with the rest of your application; rename refactorings will alter your mappings just like they should, and the compiler will fail on any typos. As for the repetition, Fluent NHibernate has a conventional configuration system, where you can specify patterns for overriding naming conventions and many other things; you set how things should be named once, then Fluent NHibernate does the rest.
Its feature includes:
- 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 our Fluent configuration API
- Database configuration - fluently configure your database in code