2010-04-30 47 views
0

實體:從父表返回ID = 0的列值選擇子對象

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

映射:在Person表

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項中的Employee表 1項(1基1級,兒童級)

查詢:var list = Session.CreateQuery("from Person").List<Person>();
返回:
0 | ID = 1
1 | ID = 0,Appointment =「Some Appointment」

+1

請問您有什麼問題? – egrunin 2010-04-30 08:45:28

回答

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

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

public virtual long ID {get;組; } - 不應該在這裏。