Skip to content

hunghq/hbm2code

Repository files navigation

hbm2code

forthebadge forthebadge

Convert NHibernate XML mapping to Code mapping

Build status

How it works

<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>
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 =>
        {
        });
    }
}

Releases

No releases published

Packages

No packages published

Languages