I'm learning about NHibernate, where the class mapping, I learned, is done with XML. I understand that Fluent NHibernate came about as a strongly-typed replacement for the XML-style of mapping. Indeed, here is the fluent-nhibernate
tag description:
Fluent NHibernate lets you write NHibernate mappings in strongly typed C# code. This allows for easy refactoring, improved readability and more concise code.
Then later I was using NHibernate Mapping Generator to create mappings and domain classes from my existing database, and it generated mapping code like this:
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's using a NHibernate.Mapping.ByCode.Conformist.ClassMapping<T>
class. What gives? If NHibernate in fact does have it's own strongly-typed, non-XML mapping capabilities, then why do I need Fluent NHibernate?
I've noticed some differences between NHibernate.Mapping.ByCode.Conformist.ClassMapping<T>
and FluentNHibernate.Mapping.ClassMap<T>
. For example, the former doesn't support References
, e.g. References(x => x.BillingItemID);
, to relate entities via the foreign key. Maybe there's another way of doing that.