エンティティフレームワークのコードで、継承を使用して共通エンティティソリューションと1対多の関係を実装しようとしています。それは望ましい結果を作りません。私はこのスキーマを必要とする:エンティティフレームワーク:1対多の関係の共通エンティティ
CommonEntity Address Licensee User
-------------- ------------- ----------- ---------
CID(PK) AddressID(PK) CID(FK/PK) CID(FK/PK)
AddressID(FK)
CommonEntity:
public class CommonEntity{
[key]
public int CID{get;set;}
public virtual List<Address> Addresses { get; set; }
}
住所:
public class Address{
[key]
public int AddressID{get;set;}
public string country{get;set;}
}
ライセンシー:
public class Licensee{
[key]
[ForeignKey("CommonEntity")]
public int CID{get;set;}
public string CompanyName{get;set;}
}
ユーザー:
public class User{
[key]
[ForeignKey("CommonEntity")]
public int CID{get;set;}
public string UserName{get;set;}
public string Pass{get;set;}
}
DbContextクラス:上記のコード
public class DataModelContext : DbContext
{
public DbSet<CommonEntity> CommonEntity { get; set; }
}
はこの例外を与えている:
ForeignKeyAttributeは、プロパティに 'CommonID' タイプ に 'TestingEF.Models.Licensee' は有効ではありません。ナビゲーションプロパティ 'CommonEntity'が依存型 'TestingEF.Models.Licensee'に見つかりませんでした。 [名前]の値は有効な ナビゲーションプロパティ名である必要があります。
あなたは '[ForeignKeyの( "CommonEntity")]を使用'、あなたはまた、ナビゲーションプロパティ 'パブリック仮想CommonEntity CommonEntityを{取得する必要があります。セット; } '。 –