开发者

Select from parent table return ID = 0 column values for child objects

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 tabl开发者_如何学编程e 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"


public class Employee : Person
{
    public Employee(){}

    public virtual long ID { get; set; }
    public virtual string Appointment { get; set; }
}

public virtual long ID { get; set; } - Not supposed to be here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜