My base table already has some register ID = 5.
How can I add the same id on the specialized table?
Example:
BaseTable
ID INT
Name Varchar(100)
DerivedTable
ID INT
Test BIT
I insert some values on the base table
Context.BaseTable.Add(new BaseTable(){ Name = '123' });
Context.SaveChanges();
The identity is 5
Now I want to add the specialized values
Context.DerivedTable.Add(new DerivedTable(){ ID = 5, Test = 1 });
Context.SaveChanges();
It didn’t work, linqpad is showing to me that sql is trying to create a new BaseTable register.
Is that any way to work around this?
Tks
If you have it mapped as inheritance (EDMX TPT, Code first TPT) you must not insert into base table separately (it should most probably be abstract class in your model). You must only insert to derived table and EF will handle insertion to both mapped tables: