在采取了关于多映射的几个解决方案后,我无法使这件事起作用
,我有这些表:
User:
intID (PK)
vcUsername
Role:
intID (PK)
vcDescription
UserRole:
intID (PK-FK)
intRole (PK-FK)
btActive
这是我的课:
public class User {
public virtual int Id {get; set;}
public virtual string Username {get;set;}
public virtual IList<UserRole> Roles {get; set;}
}
public class Role {
public virtual int Id {get; set;}
public virtual string Description {get;set;}
public virtual IList<UserRole> Users {get; set;}
}
public class UserRole {
public virtual User User {get; set;}
public virtual Role Role {get;set;}
public virtual bool IsActive {get; set;}
}
这是我的班级地图:
public UserMap() {
Table("tb_user");
Id(f => f.Id).Column("intID").GeneratedBy.Native();
Map(f => f.Username).Column("vcUsername").Not.Nullable();
HasMany(f => f.Roles).KeyColumn("intID").LazyLoad().Inverse().Cascade.All();
}
public RoleMap() {
Table("tb_role");
Id(f => f.Id).Column("intID").GeneratedBy.Native();
Map(f => f.Description).Column("vcDescription").Not.Nullable();
HasMany(f => f.Roles).KeyColumn("intRole").LazyLoad();
}
public UserRoleMap()
{
Table("tb_user_role");
References(f => f.User).Column("intID").Not.Nullable();
References(f => f.Role).Column("intRole").Not.Nullable();
Map(f => f.IsActive).Column("btActive").Not.Nullable();
}
当我运行时,我在启动时收到此错误
The entity 'UserRole' doesn't have an Id mapped
我如何正确映射这个manytomany,插入和更新工作正常?我希望你的指导清楚..谢谢