Select from parent table return ID = 0 column values for child objects
Posted
by SaD
on Stack Overflow
See other posts from Stack Overflow
or by SaD
Published on 2010-04-30T08:38:07Z
Indexed on
2010/04/30
8:47 UTC
Read the original article
Hit count: 199
nhibernate
|c#
Entities:
public class Person
{
public Person(){}
public virtual long ID { get; set; }
}
public class Employee : Person
{
public Employee(){}
public virtual long ID { get; set; }
public virtual string Appointment { get; set; }
}
Mappings:
public class PersonMap : ClassMap<Person>
{
public PersonMap()
{
Id(x => x.ID)
.GeneratedBy.Identity();
}
}
public class EmployeeMap : SubclassMap<Employee>
{
public EmployeeMap()
{
KeyColumn("ID");
Map(x => x.Appointment)
.Not.Nullable()
.Length(50);
}
}
2 items in Person table 1 item in Employee table (1 in base class, 1 in child class)
Query:var list = Session.CreateQuery("from Person").List<Person>();
Return:
0 | ID = 1
1 | ID = 0, Appointment = "SomeAppointment"
© Stack Overflow or respective owner