I have one big question about TPT + EF6.
In my database model, I have one Person table (basic information about the faces in my application), and I have tables for Supplier and Consumer .
My classes are:
//to table dbo.Person public class Person { public long Id {get; set;} //is pk public string Name {get; set;} } //to table dbo.Supplier public class Supplier : Person { public long Id {get; set;}//is pk and fk public string ProductName {get; set;} } //to table dbo.Consumer public class Consumer { public long Id {get; set;} //is pk and fk public string budget {get; set;} }
If I have one person who is both a supplier and a consumer, and I get records from the same / different DBContext or move with other objects, then EF throws an exception:
All objects in an EntitySet Person must have unique primary keys. However, an instance of type Supplier and an instance of type Consumer both have the same primary key value, EntitySet=Person;ID=20 .
Is there a way to specify a single discriminator in TPT inheritance? How to solve this problem?
inheritance c # entity-framework
Luciano castro
source share