Table Each subclass inheritance mapping by NHibernate mapping code

How to write the mapping in the new NHibernate Mapping-By-Code for each subclass strategy of this class:

public class Person
{
public virtual int Id {get; set; }
public virtual string Name {get; set; }
}

public class JuridicalPerson: Person
{
public virtual int Id {get; set; }
public virtual string LegalName {get; set; }
}

public class PrivatePerson: Person
{
public virtual int Id {get; set; }
public virtual bool Sex {get; set; }
}

This is a slightly abbreviated possible mapping

public class PersonMapping: ClassMapping
{
public PersonMapping()
{
Table("person");
Id(x => x.Id, m = > m.Generator(Generators.Native));
Property(x => x.Name);
}
}

public class JuridicalPersonMapping: JoinedSubclassMapping
{
public JuridicalPersonMapping()
{
Table("juridical_person");
Key(m => m.Column("person_id"));
Property(x => x.LegalName);
}
}

public class PrivatePersonMapping: JoinedSubclassMapping
{
public PrivatePersonMapping()
{< br /> Table("private_person");
Key(m => m.Column("person_id"));
Property(x => x.Sex);
}
}

You do not need to copy the Id attribute declaration in the derived class. It inherits from the parent class Person.

How to use this class Write the mapping in the new NHibernate Mapping-By-Code for each subclass strategy:

public class Person
{
public virtual int Id { get; set; }
public virtual string Name {get; set; }
}

public class JuridicalPerson: Person
{
public virtual int Id {get; set; }
public virtual string LegalName {get; set; }
}

public class PrivatePerson: Person
{
public virtual int Id {get; set; }
public virtual bool Sex {get; set; }
}

This is a slightly abbreviated form of possible mapping

< p>

public class PersonMapping: ClassMapping
{
public PersonMapping()
{
Table("person");
Id(x => x.Id, m => m.Generator(Generators.Native));
Property(x => x.Name);
}
}

public class JuridicalPersonMapping: JoinedSubclassMapping
{
public JuridicalPersonMapping()
{
Table("juridical_person");
Key(m => m.Column("person_id"));
Property(x => x.LegalName);
}
}

public class PrivatePersonMapping: JoinedSubclassMapping
{
public PrivatePersonMapping()
{
Table("private_person");
Key(m => m.Column("person_id"));
Property(x => x.Sex);
}
}

You do not need to copy the declaration of the Id property in the derived class. It inherits from the parent class Person.< /p>

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2838 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.