-
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
Inconsistent Equals
/GetHashCode
methods in SqlConstantExpression
#35372
Comments
Note that this has some implications regarding what options are legitimate when caching hash codes as suggested in #34149 |
Related: #29006 |
As suggested in #29006, we could consider simply not including the value in the hash code (i.e. have a fixed hash code for all SqlConstantExpressions with a given Type)... Let's think about this further. Of course, the discrepancy between the equals and hash code behavior is indeed a bug that will need to be fixed. |
Skipping the I believe this would not be much of an issue if this only occurred while placing expressions in dictionaries, but it would hurt #34149 effectiveness quite a bit. A slightly more costly option that would not involve deep hashing of the Finally, the highest-cost option is to actually hash the content of the
@roji If this makes sense to you I can push a PR with the approach you prefer. I would personally go for hashing (Note that if the assumption is that |
As a (very biased) data point, running EFCore tests against Sqlite (Microsoft.EntityFrameworkCore.Sqlite.FunctionalTests), only 45/37084 use an (I understand that this proportion is unfortunately not representative of any actual real-world scenarios) |
In EFCore, the implementation of
SqlConstantExpression
does not respect the requirements ofEquals
/GetHashCode
since ff99dc3, specifically(from https://learn.microsoft.com/en-us/dotnet/api/system.object.gethashcode)
This snippet emits
on EFCore 3.0.0 and
on EFCore 3.1, 6, 8.
Note that because of #35355 the snippet is meaningless on EFCore 9.
The corresponding one is
which emits
This inconsistency is caused by the "deep" check for
IList
inSqlConstantExpression.ValueEquals
.Assuming that is intentional and needed, a corresponding hash construction should probably also be performed.
The text was updated successfully, but these errors were encountered: