1
我重新实现了成员资格提供者并希望保留原始DB方案。我有2类:如何在同一属性中定义PK和FK
class UserProfile
{
public int UserId {get;set} //PK
......
}
class Membership
{
public int UserId {get;set;} //FK to UserProfile.UserId
.........
}
现在我附上Membership.UserId为FK使用FluentAPI到UserProfile.UserId,我想这也是对PK成员关系表。
我可以保证UserProfile.UserId是数据库生成的身份,不会重复。 我尝试了以下代码,但在创建迁移过程中出现错误时失败:
类型中的每个属性名称都必须是唯一的。属性名称'UserId'已经被定义。
HasKey(k => k.UserId); //Declare it as PK !!!!
Map(m => m.ToTable("webpages_membership")); //Setup table name
HasRequired(t => t.User) //Nav.property to the UserProfile
.WithRequiredDependent(t1 => t1.Membership) //Rev.nav.property from the UserProfile
.Map(m => m.MapKey("UserId")); //FK to the UserProfile !!!!
如果我除去惊叹号标志标迁移任何行创建罚款,但有错误的列名。