2013-05-10 141 views
1

我有下面的類中,它具有相同類型的父母,如何映射到父在同一個表使用C#(ClassMapping)

public class Unit 
{ 
    public virtual int UnitKey { get; set; } 
    public virtual string UnitName { get; set; } 
    public virtual string UnitType { get; set; } 
    public virtual Unit Parent { get; set; } 
    public virtual User UnitLeader { get; set; } 
} 

NHibernate的在數據庫中有一個表所謂單位

Unit_Key (int) 
Unit_Name (varchar) 
Unit_Type (varchar) 
Parent_Key (varchar) 
User_Key (int) 

,這裏是如何映射類,

internal class UnitMapping : ClassMapping<Unit> 
{ 
    public UnitMapping() 
    { 
     Id(x => x.UnitKey, map => 
     { 
      map.Column("Unit_Key"); 
      map.Generator(Generators.Assigned); 
     }); 
     Property(x => x.UnitName, map => 
     { 
      map.Column("Unit_Name"); 
      map.NotNullable(true); 
     }); 
     Property(x => x.UnitType, map => 
     { 
      map.Column("Unit_Type"); map.NotNullable(true); 
     }); 

     ManyToOne(x => x.UnitLeader, map => 
     { 
      map.Column("User_Key"); map.Cascade(Cascade.None); 
     }); 
    } 
} 

我怎麼能映射父(類型同等級的)這是在同一個表中。

謝謝

回答

0

完全一樣的方式,你做一個不同的實體。

您已經繪製了一個ManyToOneUnitLeader); Parent沒有什麼不同。

+0

感謝您的回答。 – 2013-05-13 15:51:59

+0

如果它解決了您的問題,請不要忘記將其標記爲已接受。 – 2013-05-13 15:53:12

+0

使用此映射級聯刪除嗎? – 2013-08-06 08:16:32

相關問題