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

Remove unnecessary where clause when querying a base class #19803

Closed
DibyodyutiMondal opened this issue Feb 5, 2020 · 2 comments
Closed

Remove unnecessary where clause when querying a base class #19803

DibyodyutiMondal opened this issue Feb 5, 2020 · 2 comments

Comments

@DibyodyutiMondal
Copy link

DibyodyutiMondal commented Feb 5, 2020

What problem are you trying to solve?

Say I have one base class with multiple derived classes. if I want to query something based on a predicate that involves properties of the base class only, then EF Core generates a query that has an extra where clause involving the discriminator column.
First, the extra where clause would do absolutely nothing to help the query in any way, The predicate will return true for all rows in the result set.
Second, I think that if I were to make a covering index for the query in question, then I'd have to include the discriminator column in the index, (do excuse me if I'm wrong here)

Describe the solution you'd like

If we are querying on the DBSet of a base class, the clause should be omitted

Note

This problem is especially true for TPH mapping. I imagine that when the TPT mapping finally ships in EF Core, it will probably solve this issue outright, but the problem will remain for those unable to shift to TPT from TPH

@ajcvickers
Copy link
Member

@DibyodyutiMondal

if I want to query something based on a predicate that involves properties of the base class only

A query can use only properties defined in the base class, but still return instances of multiple different types in the hierarchy. So, "involves properties of the base class only" does not mean the same as "involves any type in the hierarchy".

Issue #18106 is tracking an optimization that would result in no where clause for discriminators when querying for all types of entity in the hierarchy. Is this what you're looking for?

@DibyodyutiMondal
Copy link
Author

Yes, that one is exactly it. Closing as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants