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);
});
}
}
我怎麼能映射父(類型同等級的)這是在同一個表中。
謝謝
感謝您的回答。 – 2013-05-13 15:51:59
如果它解決了您的問題,請不要忘記將其標記爲已接受。 – 2013-05-13 15:53:12
使用此映射級聯刪除嗎? – 2013-08-06 08:16:32