1

我正在使用實體框架4.1和代碼優先映射。實體框架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 
    { 
    pubic 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); 
    } 

好吧,問題很簡單,你在哪裏犯錯?

謝謝馬丁

回答