-
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
QueryRewrite: when comparing entity with composite key to null, only check it's first key property, rather than all of them #15080
Comments
@maumar What if one key value is null and the other is non-null? This should be treated as a null key, but the first property may not be null. |
@ajcvickers - We may have code in place right now which checks only first null key rather than all of them. Since none of the key should be null if stored to database by EF. Is there any incorrect assumption here? |
@smitpatel If any part of a composite key is null, then the whole key is considered null. So I think the assumption is correct. |
So you need to tell us what is correct query for above linq. In current source code, we do generate expected SQL. But it is just checking first property being not null. |
@smitpatel If the first value is null => key is null. If the first value is non-null => we don't know if the key is null or not. So we can't "only check its first property" but we can short-circuit the decision as soon as we find a null value. If that's what we're doing already, then fine. If that's what we're going to do, then fine. The issue filed doesn't say that. It says we only need to check the value of one property, and that's not fine. |
The current SQL only checks first property being non null when translating entity is non-null. |
So it's a bug in entity equality rewrite. Bump priority? |
Re-triage. |
See #20164 |
efcore/src/EFCore/Query/Internal/EntityEqualityRewritingExpressionVisitor.cs Lines 889 to 895 in 7166201
|
Following @ajcvickers statement
please review @ajcvickers @AndriySvyryd |
Resolves #15080 Implemented behavior: - If any part of composite key is null then key is null. - If comparing entity with null then check if "any" key value is null. - If comparing entity with non-null then check if "all" key values are non null. Resolves #20344 Resolves #19431 Resolves #13568 Resolves #13655 Since we already convert property access to nullable, if entity from client is null, make key value as null. Resolves #19676 Clr type mismatch between proxy type and entity type is ignored. Resolves #20164 Rewrites entity equality during translation Part of #18923
Resolves #15080 Implemented behavior: - If any part of composite key is null then key is null. - If comparing entity with null then check if "any" key value is null. - If comparing entity with non-null then check if "all" key values are non null. Resolves #20344 Resolves #19431 Resolves #13568 Resolves #13655 Since we already convert property access to nullable, if entity from client is null, make key value as null. Resolves #19676 Clr type mismatch between proxy type and entity type is ignored. Resolves #20164 Rewrites entity equality during translation Part of #18923
Resolves #15080 Implemented behavior: - If any part of composite key is null then key is null. - If comparing entity with null then check if "any" key value is null. - If comparing entity with non-null then check if "all" key values are non null. Resolves #20344 Resolves #19431 Resolves #13568 Resolves #13655 Since we already convert property access to nullable, if entity from client is null, make key value as null. Resolves #19676 Clr type mismatch between proxy type and entity type is ignored. Resolves #20164 Rewrites entity equality during translation Part of #18923
Resolves #15080 Implemented behavior: - If any part of composite key is null then key is null. - If comparing entity with null then check if "any" key value is null. - If comparing entity with non-null then check if "all" key values are non null. Resolves #20344 Resolves #19431 Resolves #13568 Resolves #13655 Since we already convert property access to nullable, if entity from client is null, make key value as null. Resolves #19676 Clr type mismatch between proxy type and entity type is ignored. Resolves #20164 Rewrites entity equality during translation Part of #18923
Resolves #15080 Implemented behavior: - If any part of composite key is null then key is null. - If comparing entity with null then check if "any" key value is null. - If comparing entity with non-null then check if "all" key values are non null. Resolves #20344 Resolves #19431 Resolves #13568 Resolves #13655 Since we already convert property access to nullable, if entity from client is null, make key value as null. Resolves #19676 Clr type mismatch between proxy type and entity type is ignored. Resolves #20164 Rewrites entity equality during translation Part of #18923
Extends fix for #15080 to navigation expansion too where we check for outerKey != null before correlation predicate.
Extends fix for #15080 to navigation expansion too where we check for outerKey != null before correlation predicate.
Query:
Expected:
current:
Tests affected:
Select_null_propagation_negative4
Select_null_propagation_negative5
The text was updated successfully, but these errors were encountered: