【发布时间】:2014-10-08 10:09:01
【问题描述】:
我不确定如何在给定实体下方进行映射。
下面是表格。
Employee { ID, Name, Role_ID } (Role_ID is foreign key from Role table)
Role {Role_ID, Name }
以下是类:
class Employee
{
public virtual string ID { get; set; }
public virtual string Name { get; set; }
public virtual Role EmpRole { get; set; }
}
class Role
{
public virtual string RoleID { get; set; }
public virtual string Name { get; set; }
}
以下是映射:
public class EmployeeMap : ClassMap<Employee>
{
public EmployeeMap()
{
Table("Employee");
Id(x => x.ID, "ID");
Map(x => x.Name, "NAME");
//for relationship not sure which mapping to be used???
}
}
public class RoleMap : ClassMap<Role>
{
public RoleMap()
{
Table("Role");
Id(x => x.RoleID, "ROLE_ID");
Map(x => x.RoleID, "ROLE_ID");
Map(x => x.Name, "ROLE_NAME");
//For relationship not sure what to be used????
}
}
场景:一名员工将担任一个角色。一个角色可以分配给多个员工。
请建议我如何编写两个实体的关系?
【问题讨论】:
标签: c#-4.0 nhibernate fluent-nhibernate fluent