我想我在這裏有一個設計問題。流利的nhibernate一對多收集,通過enum過濾
基本上我已經叫辦公室
class Office
{
public virtual long Id { get; set; }
public virtual string Code { get; set; }
public virtual IList<Person> Managers { get; set; }
public virtual IList<Person> Developers { get; set; }
public virtual IList<Person> TeaMakers { get; set; }
}
和一個名爲Person
class Person
{
public virtual long Id { get; set; }
public virtual string Name {get; set;}
public virtual StaffType Type { get; set;}
public virtual Office Office { get; set; }
}
類和一個名爲StaffType
public enum StaffType
{
MANAGER,
DEVELOPER,
TEAMAKER
}
映射Person表枚舉類很簡單:
public class PersonMap: ClassMap<Person>
{
public PersonMap()
{
Table("Person");
Id(x => x.Id);
Map(x => x.Name);
References(x => x.Office).ForeignKey("Id").Not.Nullable()
Map(x => x.Type).CustomType<StaffType>();
}
}
但我難住在辦公室地圖上。如何讓地圖使用枚舉過濾3個列表?
如果我這樣做:
public class OfficeMap: ClassMap<Office>
{
public static string TableName = "Office";
public static string MappingColumn = TableName + "Id";
public OfficeMap()
{
Table(TableName);
Id(x => x.Id);
Map(x = x.Code);
HasMany(x => x.Managers)
.Cascade.AllDeleteOrphan()
.Fetch.Select()
.Inverse().KeyColumn(MappingColumn);
HasMany(x => x.Developers)
.Cascade.AllDeleteOrphan()
.Fetch.Select()
.Inverse().KeyColumn(MappingColumn);
HasMany(x => x.TeaMakers)
.Cascade.AllDeleteOrphan()
.Fetch.Select()
.Inverse().KeyColumn(MappingColumn);
}
}
流暢度不會有foggiest知道如何通過StaffType枚舉
感謝您的幫助
額外注分裂3個收藏了起來: Person表的Type類型字段allways被映射爲int。