Skip to content

Please clarify "inheritance hierarchy" limitation #1239

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

Closed
IndigoHealth opened this issue Jan 17, 2019 — with docs.microsoft.com · 4 comments · Fixed by #1906
Closed

Please clarify "inheritance hierarchy" limitation #1239

IndigoHealth opened this issue Jan 17, 2019 — with docs.microsoft.com · 4 comments · Fixed by #1906

Comments

Copy link

This article states:

> Current shortcomings
> Inheritance hierarchies that include owned entity types are not supported

I interpreted this to mean that entities that are in an inheritance hierarchy cannot include owned entities. But, according to this GitHub discussion the limitation means that the owned entities themselves cannot be part of an inheritance hierarchy. Please clarify this detail.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Copy link

I've tested this in EFCore 2.2.
In fact, if we make more clarifications in the DbContext.OnModelCreating, for the included/owned entity, then this "Inheritance hierarchies that include owned entity types" still working.
For example, we have parent class User, and child class Teacher, if we have class UserContactInfo which owned by User with clarification:
modelBuilder.Entity().OwnsOne(typeof(UserContactInfo), "UserContactInfo");
then we don't need to do so much clarifications for this UserContactInfo entity, only need
modelBuilder.Entity(entity => { entity.ToTable("UserContactInfo");});
is enough.
But if the class UserContactInfo owned by Teacher class (not by User class), with clarification
modelBuilder.Entity().OwnsOne(typeof(UserContactInfo), "UserContactInfo");
(sure, we don't need the Entity().OwnsOne(...UserContactInfo) statement now, since User no longer owned the UserContactInfo),
then we need to add one more statement into the clarification:
modelBuilder.Entity(entity =>
{
entity.HasKey("UserID");
entity.ToTable("UserContactInfo");
});
In above way, no matter the parent class, or the child class, they all can own their entities, while the EFCore will fire the SQL with "[User] left join [UserContactInfo]" content.

Copy link

laguer71 commented Oct 2, 2019

This works because the owned types are mapped to a different table? Have you tried seeding data to the inherited member? have you tried doing table splitting instead of a different table? I tried and did not work for me... would like to know if I'm doing something wrong

@AndriySvyryd
Copy link
Member

@laguer71 Those scenarios are supported. If you are getting errors create and issue on https://github.com/aspnet/EntityFrameworkCore/issues with a small repro project, preferably targeting 3.0.0

Copy link

@laguser71 Agree with above comment. Before creating issue on Github, you can also check for my blogs for more detail example. It is about using table split & owned types together. But sorry, they are in Chinese, but the source code and screen shots are all English. So just scroll the source code & screen part is enough. The URLs are: https://www.cnblogs.com/fatkent/p/10436274.html & https://www.cnblogs.com/fatkent/p/10436991.html

@AndriySvyryd AndriySvyryd removed their assignment Nov 6, 2019
AndriySvyryd added a commit that referenced this issue Nov 6, 2019
AndriySvyryd added a commit that referenced this issue Nov 10, 2019
AndriySvyryd added a commit that referenced this issue Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants