实体多对多关系,Entityframework自动生成的数据库中Role_RoleID有什么用?
实体类定义如下:
public class User
{
[Key]
public int UserID { get; set; }
/// <summary>
/// 用户名
/// </summary>
[Required(ErrorMessage = "必填")]
[StringLength(20, MinimumLength = 4, ErrorMessage = "{1}到{0}个字符")]
[Display(Name = "用户名")]
public string UserName { get; set; }
……
public virtual ICollection<UserRoleRelation> UserRoleRelations { get; set; }
}
public class Role
{
[Key]
public int RoleID { get; set; }
[Required(ErrorMessage ="必填")]
[StringLength(20,MinimumLength =2,ErrorMessage ="{1}到{0}个字")]
[Display(Name ="名称")]
public string Name { get; set; }
……
public virtual ICollection<UserRoleRelation> UserRoleRelations { get; set; }
}
public class UserRoleRelation
{
[Key]
public int RelationID { get; set; }
/// <summary>
/// 用户ID
/// </summary>
[Required()]
public int UserID { get; set; }
/// <summary>
/// 角色ID
/// </summary>
[Required()]
public int RoelID { get; set; }
}
生成的数据库结构如下,请问Role_RoleID有什么用?
那是因为Role表的主键与UserRoleRelation表的外键不一致,一个是RoleID,一个是RoelID
一致的啊
@RunningYY: Role表里面是RoleIDUserRoleRelation表里面是RoelID el和le看好
@云—: 是这样的,谢谢哦!
看着没有用,估计是你生成过两遍,然后改过UserRoleRelation中的RoelID的属性名
直接删除就可以了
不是