Convert NHibernate XML mapping to Code mapping
Input Hbm mapping files
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Worker" abstract="true">
<id name="Id" type="Int64">
<generator class="assigned" />
</id>
<discriminator column="Type" />
<property name="Name" />
</class>
<subclass discriminator-value="DW" name="DomesticWorker">
<property name="SocialSecurityNo" />
</subclass>
<subclass discriminator-value="FW" name="ForeignWorker">
<property name="PassportNo" />
</subclass>
</hibernate-mapping>
Output Classes with Mapping by Code
public class WorkerMap : ClassMapping<Worker>
{
public WorkerMap()
{
Abstract(true);
Table("Worker");
Id(x => x.Id, m =>
{
m.Generator(Generators.Assigned);
m.Type(NHibernateUtil.Int64);
});
Discriminator(m =>
{
m.Column("Type");
});
Property(x => x.Name, m =>
{
});
}
}
public class DomesticWorkerMap : SubclassMapping<DomesticWorker>
{
public DomesticWorkerMap()
{
DiscriminatorValue("DW");
Property(x => x.SocialSecurityNo, m =>
{
});
}
}
public class ForeignWorkerMap : SubclassMapping<ForeignWorker>
{
public ForeignWorkerMap()
{
DiscriminatorValue("FW");
Property(x => x.PassportNo, m =>
{
});
}
}