【发布时间】:2011-07-25 20:33:45
【问题描述】:
您好,我计划在我的一个项目中测试 EF Code First。这就是我真正想要的。 我有三个表,结构如下
public partial class App_user
{
public int id { get; set; }
public string name { get; set; }
public string email_address { get; set; }
public string password { get; set; }
public int user_type { get; set; }
public List<Role> Roles { get; set; }
}
public partial class Role
{
public int id { get; set; }
public string name { get; set; }
}
public partial class User_role
{
public int user_id { get; set; }
public int role_id { get; set; }
public virtual Role Role { get; set; }
public virtual App_user App_user { get; set; }
}
在第三个表中没有主键。所以它在运行时会出错。这是错误消息 -
System.Data.Edm.EdmEntityType: : EntityType 'User_role' 没有键 定义。为此定义密钥 实体类型。 System.Data.Edm.EdmEntitySet: EntityType:EntitySet User_roles 基于类型 User_role 没有 已定义键。
为什么会这样?有解决方案吗?
【问题讨论】:
标签: c# entity-framework ef-code-first entity-framework-4.1