What is the difference between NHibernate.Mapping.ByCode.Conformist.ClassMapping and FluentNHibernate.Mapping.ClassMap?

I am learning NHibernate where, as I found out, class mapping is done with XML. I understand that Fluent NHibernate has emerged as a strongly typed replacement for the XML mapping style. In fact, here is a description of the fluent-nhibernate tag:

Fluent NHibernate lets you write NHibernate mappings in strongly typed C #. This allows for easy refactoring, improved readability, and more concise code.

Then I used the NHibernate Mapping Generator to create the mappings and domain classes from my existing database, and it generated the mapping code as follows:

 using NHibernate.Mapping.ByCode.Conformist; using NHibernate.Mapping.ByCode; namespace MyNamespace.Infrastructure.Mappings { public class MyItemMapping : ClassMapping<MyItem> { public MyItemMapping() { Table("MyItems"); Schema("master"); Lazy(true); Id(x => x.ID, map => map.Generator(Generators.Assigned)); Property(x => x.Status, map => map.NotNullable(true)); Property(x => x.DueDate, map => map.NotNullable(true)); Property(x => x.NextReminderDate); Property(x => x.DatePaid); Property(x => x.Notes); } } } 

Lo and behold, it uses the NHibernate.Mapping.ByCode.Conformist.ClassMapping<T> class. What gives? If NHibernate really has its own typed, non-XML display capabilities, then why do I need Fluent NHibernate?

I noticed some differences between NHibernate.Mapping.ByCode.Conformist.ClassMapping<T> and FluentNHibernate.Mapping.ClassMap<T> . For example, the first does not support References , for example. References(x => x.BillingItemID); to bind objects through a foreign key. Maybe there is another way to do this.

+3
source share
1 answer

FluentNHibernate was around before NHibernate had a MappingByCode, now that it does, FluentNHibernate is deprecated, it is also less efficient than Nhibernate, its own MappingByCode, because it generates normal XML mapping files at startup and uses them internally.

The only drawback of NHibernate MappingByCode is that the documentation is not enough for it, the best I found is here:

http://notherdev.blogspot.co.uk/2012/02/nhibernates-mapping-by-code-summary.html

But I would use the NHibernate version independently. I get the impression that the NHibernate version actually supports more than FluentNhibernate, and the equivalent of this Reference will be just the opposite side of the relationship, for example. if the parent is displayed as OneToMany() , then the equivalent child side map for the Fluent Reference will be ManyToOne() . I think that is the case anyway.

+7
source

All Articles