вот код, который я использую:
открытый класс AccountabilityMap: ClassMap
{
public AccountabilityMap ()
{
Схема ( "organizationstructure");
Not.LazyLoad ();
Id (p => p.Id);
References(p => p.AccountabilityType)
.Not.Nullable();
References(p => p.Child)
.Column("ChildPartyId")
.Not.LazyLoad()
.Not.Nullable();
References(p => p.Parent)
.Column("ParentPartyId")
.Not.LazyLoad()
.Not.Nullable();
}
}
открытый класс PartyMap: ClassMap
{
public PartyMap ()
{
Схема ( "organizationstructure");
Id(p => p.Id);
HasMany (p => p.Children)
.LazyLoad ()
.Cascade.AllDeleteOrphan ()
.Inverse ()
.KeyColumn ( "ParentPartyId");
HasMany(p => p.Parents)
.LazyLoad()
.Inverse()
.Cascade.AllDeleteOrphan()
.KeyColumn("ChildPartyId");
}
}
открытый класс DepartmentMap: SubclassMap
{
публичный DepartmentMap ()
{
Schema("organizationstructure");
KeyColumn("PartyId");
Map(p => p.DepartmentType)
.Not.Nullable()
.CustomSqlType("tinyint")
.CustomType<DepartmentType>()
.Length(1);
HasManyToMany(p => p.DepartmentGroup)
.Table("DepartmentGroupToDepartment")
.Schema("formation");
}
}
выбор отделов:
_department = Родители // =====> родители: IList
.Where (p => p.AccountabilityType.Id == (int) AccountabilityTypeDbId.ParentDepartmentOfPerson)
.Select (p => p.Parent)
.В ролях()
.SingleOrDefault ();