从父表中选择返回ID = 0子对象的列值

时间:2010-04-30 08:38:08

标签: c# nhibernate

实体:

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; }
}

映射:

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

Person表中的2个项目 员工表中的1项 (1个基础班,1个孩子班)

查询:var list = Session.CreateQuery("from Person").List<Person>();
返回:
0 | ID = 1
1 | ID = 0,约会=“SomeAppointment”

1 个答案:

答案 0 :(得分:0)

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

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

public virtual long ID {get;组; } - 不应该在这里。

相关问题