Vote count: 0
I'm trying to implement one-many relationship with common entity solution in entity framework code first using inheritance. Its not creating desired results. I need this schema:
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; }
}
Address:
public class Address{
[key]
public int AddressID{get;set;}
public string country{get;set;}
}
Licensee:
public class Licensee{
[key]
[ForeignKey("CommonEntity")]
public int CID{get;set;}
public string CompanyName{get;set;}
}
User:
public class User{
[key]
[ForeignKey("CommonEntity")]
public int CID{get;set;}
public string UserName{get;set;}
public string Pass{get;set;}
}
DbContext Class:
public class DataModelContext : DbContext
{
public DbSet<CommonEntity> CommonEntity { get; set; }
}
Above code is giving this exception:
The ForeignKeyAttribute on property 'CommonID' on type 'TestingEF.Models.Licensee' is not valid. The navigation property 'CommonEntity' was not found on the dependent type 'TestingEF.Models.Licensee'. The Name value should be a valid navigation property name.
asked 25 secs ago
Entity Framework: Common entity for one-to-many relationship
Aucun commentaire:
Enregistrer un commentaire