1
情景似乎很微不足道,我真的很困惑我做錯了什麼。實體框架和使用Fluent API將兩個實體映射到另一個
所以,我有一個客戶端類
public class Client
{
[Key]
public int ClientID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public virtual Account Account { get; set; }
}
Employee類
public class Employee
{
[Key]
public int EmployeeID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public virtual Account Account { get; set; }
}
和賬戶類
public class Account
{
[Key]
public int AccountID { get; set; }
public string Login { get; set; }
public string Password { get; set; }
public virtual Employee Employee { get; set; }
public virtual Client Client { get; set; }
}
客戶和僱員可能有一個帳戶,或不(在線訪問是可選的)。由於數據庫與EF namingconvention不兼容,我必須提供Fluent API顯式映射。
客戶端和員工表都有我試圖用來建立關係的「AccountID」列。
modelBuilder.Entity<Client>()
.HasOptional(e => e.Account)
.WithRequired(a => a.Client)
.Map(m => m.MapKey("AccountID"));
modelBuilder.Entity<Employee>()
.HasOptional(e => e.Account)
.WithRequired(a => a.Employee)
.Map(m => m.MapKey("AccountID"));
,但我得到
Schema specified is not valid. Errors:
(15,6) : error 0019: Each property name in a type must be unique. Property name 'AccountID' was already defined.
(16,6) : error 0019: Each property name in a type must be unique. Property name 'AccountID' was already defined.
那麼,有沒有辦法比的表/實體結構的改變來解決這個其他?