シナリオは些細なことのようで、私は自分が間違っていることについて本当に混乱しています。
だから、私はクライアントクラスを持っています
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; }
}
従業員クラス
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ネーミングコンベンションと互換性がないため、FluentAPIの明示的なマッピングを考え出す必要があります。
ClientテーブルとEmployeeテーブルの両方に、リレーションを構築するために使用しようとしている「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.
それで、テーブル/エンティティ構造の変更以外にこれを修正する方法はありますか?