EF 6 using TPT errors have the same primary key value

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?

+7
inheritance c # entity-framework
source share

No one has answered this question yet.

See similar questions:

2
ADO.NET Entity Framework: can I have multiple entity types for the same string

or similar:

1270
Why not inherit from List <T>?
141
EF Code First "Invalid discriminator column name but without inheritance
113
ASP.NET MVC - The binding of an object of type "MODELNAME" failed because another object of the same type already has the same primary key value
6
Display TPT in EF code First 4.1 w / Various primary keys
3
EF TPT generating duplicate foreign keys
3
Table for hierarchy and composite primary key
one
All objects in an EntitySet must have unique primary keys.
one
The basic principle of identifying a key class of TPT
one
An object with the same primary key in TPC inheritance
0
Entity Framework 6 says that two records have the same primary key, although they are in completely different tables

All Articles