Entity framework 实体框架4.1代码优先映射问题

Entity framework 实体框架4.1代码优先映射问题,entity-framework,database-design,entity-framework-4.1,mapping,Entity Framework,Database Design,Entity Framework 4.1,Mapping,我使用的是实体框架4.1和代码优先映射 public class Account { public Int AccountId {get;set}; public string Name {get;set}; public int? ProfileId {get;set;} public virtual Profile {get;set;} } public class Profile { public int ProfileId {get;set;}

我使用的是实体框架4.1和代码优先映射

public class Account
{
    public Int AccountId {get;set};
    public string Name {get;set};
    public int? ProfileId {get;set;}
    public virtual Profile {get;set;}

}

public class Profile
{
    public int ProfileId {get;set;}
    public DateTime Created {get;set;}
    public virtual Account {get;set;} // navigation back to account
}

public AccountMapper()
{
    ToTable("..")
    HasKey(x => x.AccountId);
    HasOptional(x => x.Profile).WithRequired(x => x.Account) // invalid column exception
    // Try HasOptional(x => x.Profile).WithRequired(x => x.Account).Map(x => x.MapKey("ProfileId")) // rror 0019: Each property name in a type must be unique. Property name 'ProfileId' was already defined.
}

public ProfileMappeR()
{
    ToTable("..")
    HasKey(x => x.ProfileId);
}
问题很简单:你在哪里犯错


谢谢,Martin。

一对一关系对于代码优先来说有点特殊。下面是一篇关于它的好博客文章:


干杯

一对一关系对于代码优先来说有点特殊。下面是一篇关于它的好博客文章:

干杯