我使用Join方法将两个具有一对一关系的表映射为单个类:
public class StoreMap: ClassMap<Store>
{
public StoreMap()
{
Schema("ST");
Table("Store");
Id(x => x.StoreId, "storeId").UnsavedValue(0).GeneratedBy.Identity();
//...
Join("EmployeeManagesStore", y => {
y.Schema("HR").Optional().KeyColumn("storeId");
y.References(x => x.Manager, "employeeId")
});
}
}
我需要映射Employee
类一侧的一对多属性。我怎样才能做到这一点?我设法做到这一点的唯一方法是使用HasManyToMany
代替HasMany
,但它似乎并不正确:
public class EmployeeMap: ClassMap<Employee>
{
public EmployeeMap()
{
Schema("HR");
Table("Employee");
Id(x => x.EmployeeId, "employeeId").UnsavedValue(0).GeneratedBy.Identity();
//...
HasManyToMany(x => x.ManagedStores).BatchSize(100)
.Schema("HR").Table("EmployeeManagesStore")
.ParentKeyColumn("employeeId")
.ChildKeyColumn("storeId")
.Cascade.None();
}
}
基本上这是表的数据库模式:
Store ---1:1--- EmployeeManagesStore ---N:1--- Employee