0
好吧,我很新的Fluent和NHibernate,我不知道如何映射這種特定的關係,存在於我的數據庫。我有下面的ER圖,概述了我的表結構。流利的NHibernate的對象化/相關關係映射
下面是我當前的C#實體類和流利的映射:
public class GroupHeader
{
public virtual Guid Id { get; private set;}
public virtual string Name { get; set; }
public virtual string Description { get; set; }
public virtual IList<RightHeader> AllowedRights { get; set; }
public virtual IList<RightHeader> DeniedRights { get; set; }
public virtual IList<RightHeader> UnsetRights { get; set; }
}
public class RightHeader
{
public virtual decimal Num { get; private set; }
public virtual string Name { get; set; }
public virtual string Description { get; set; }
}
public class GroupHeaderMap : ClassMap<GroupHeader>
{
public GroupHeaderMap()
{
Table("GROUP_HEADER");
Id(x => x.Id, "GROUP_ID");
Map(x => x.Name, "GROUP_NAME").Unique();
Map(x => x.Description, "GROUP_DESCRIPTION");
HasManyToMany(x => x.AllowedRights)
.Table("GROUP_RIGHT_COMPOSITE")
.ParentKeyColumn("GROUP_ID")
.ChildKeyColumn("RIGHT_NUM")
.Where("RIGHT_VALUE = 1")
.Cascade.SaveUpdate();
HasManyToMany(x => x.DeniedRights)
.Table("GROUP_RIGHT_COMPOSITE")
.ParentKeyColumn("GROUP_ID")
.ChildKeyColumn("RIGHT_NUM")
.Where("RIGHT_VALUE = -1")
.Cascade.SaveUpdate();
HasManyToMany(x => x.UnsetRights)
.Table("GROUP_RIGHT_COMPOSITE")
.ParentKeyColumn("GROUP_ID")
.ChildKeyColumn("RIGHT_NUM")
.Where("RIGHT_VALUE = 0")
.Cascade.SaveUpdate();
}
}
public class RightHeaderMap : ClassMap<RightHeader>
{
public RightHeaderMap()
{
Table("RIGHT_HEADER");
Id(x => x.Num, "RIGHT_NUM");
Map(x => x.Name, "RIGHT_NAME");
Map(x => x.Description, "RIGHT_DESCRIPTION");
}
}
目前每當我創建一個新的頁眉和填充它未能插入這些記錄的AllowedRights成員變量,因爲RIGHT_VALUE列在GROUP_RIGHT_COMPOSITE中不允許使用空值。我不太清楚如何在流利地圖中繪製這個圖或者我應該在我的實體中真正處理這個問題。任何幫助,將不勝感激。