Skip to content
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

Using a Discriminator that is part of a composite key #18126

Closed
sitepodmatt opened this issue Sep 29, 2019 · 1 comment
Closed

Using a Discriminator that is part of a composite key #18126

sitepodmatt opened this issue Sep 29, 2019 · 1 comment
Labels
area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@sitepodmatt
Copy link

sitepodmatt commented Sep 29, 2019

Using EF Core 3.0 release. If we have an abstract base class of Animal and two empty dervied classes of Dog and Cat


class Animal
Name : String
TypeOfAnimal : String
Age : int
Parent : Animal?

class Dog : Animal
class Cat : Animal

And a defined database context of

        mb.Entity<Animal>().HasKey(x => new {x.Name, x.TypeOfAnimal});
        mb.Entity<Entity>().HasDiscriminator<string>(x => x.TypeOfAnimal);
        mb.Entity<Dog>().HasBaseType<Animal>();
        mb.Entity<Cat>().HasBaseType<Animal>();

With Primary Key (Name, TypeOfAnimal) attempting to use TypeOfAnimal as a discriminator does not work correctly.
The discriminator value is not populated automatically and .Parent is not resolved to the derived type but to the base type (lets presume that parent of a cat can be a dog).

Adding a supplementary TypeOfAnimal2 : String, not attached to any key, then discriminating on that works both on the fetched Animal and .Parent reference as expected.

Is this a design limitation or a bug?

@smitpatel smitpatel added this to the Backlog milestone Sep 30, 2019
@AndriySvyryd AndriySvyryd self-assigned this Mar 20, 2020
@ajcvickers ajcvickers modified the milestones: Backlog, 6.0.0 Nov 5, 2020
@AndriySvyryd AndriySvyryd modified the milestones: 6.0.0, Backlog Sep 22, 2021
@AndriySvyryd AndriySvyryd added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Sep 22, 2021
AndriySvyryd added a commit that referenced this issue Sep 22, 2021
Optimize the discriminator value in the runtime model

Fixes #18126
AndriySvyryd added a commit that referenced this issue Sep 22, 2021
Optimize the discriminator value in the runtime model

Fixes #18126
@AndriySvyryd
Copy link
Member

Fixed in 3b67c3d

@AndriySvyryd AndriySvyryd removed their assignment Sep 22, 2021
@ajcvickers ajcvickers modified the milestones: Backlog, 6.0.0 Sep 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

No branches or pull requests

4 participants