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.
source share