-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EF Core code first Inheritance of separate tables #8728
Comments
I am guessing you are looking for Table Per Type inheritance, which is very needed feature not yet implemented. You can look here #2266 for more info. |
It seems so, and looks like it's not implemented yet. public abstract class CompanyBase
{
[Required]
public string Name { get; set; }
[MaxLength(50)]
public string Uid { get; set; }
...
} public class Company : CompanyBase
{
public Guid CompanyId { get; set; }
} public class CompanyHistory : CompanyBase
{
public Guid CompanyHistoryId { get; set; }
public Guid CompanyId { get; set; }
public virtual Company Company { get; set; }
public DateTime EffectiveDate { get; set; }
public DateTime? DeffectiveDate { get; set; }
} |
@borisdj We typically refer to this type of mapping as TPC. This is being tracked by issue #3170, so I'm going to close this issue as a duplicate of that one. The workaround that you posted should work as long as CompanyBase is not mapped. This implies that there cannot be any references from entity types to the CompanyBase class--they must all reference one of the derived classes. |
Yes, and CompanyBase is not mapped, I have just added 'abstract': |
Say I have a table Company defined in following entity:
And I need another table CompanyHistory that will have all fields of Company extended with
CompanyHistoryId, EffectiveDate, DEffectiveDate
.I have tried it like this:
But instead of 2 tables, migration makes only 1 table 'Company' where it combines all the columns.
I could get what I want like this:
But can the same be achieved using inheritance, so that I don't have to write all the columns again.
Further technical details
EF Core version: 1.1.2
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: Visual Studio 2017
The text was updated successfully, but these errors were encountered: