Closed maximgorbatyuk closed 5 years ago
I added a test for it and I can't reproduce it. IsCacheHit
is always false
here, which means it doesn't read the value from the cache, when it's using different random values.
Sorry for late response, @VahidN .
I have tried some ways to reproduce an it seems like the bug will appear when I use "Invariant" comparing.
Look to the screenshots below:
When I use `string.Equals("ololo", InvariantCultureIgnoreCase) the bug appears:
When I use string.ToUpperInvariant() == string.ToUpperInvariant()
the bug appears:
When I use just string.Lower() == string.Lower()
the bug does not appear:
Here is a piece of code to make yor way to reproduce the bug more easy: https://gist.github.com/maximgorbatyuk/4a48e227e7f47d3097860b58678059f0
Collations
. When you are working with for instance the SQL Server, you don't need to use ToUpper
or ToLower
in your queries. Why? Because the SQL Server will use its current Collation
to handle it. more infoToUpperInvariant
in your Linq to Entities queries, EF will switch to the client side evaluation
to handle it. in this case, you think it will add your parameters to the final SQL, but it won't. It will create a general SQL without any parameters and then it will filter the result on the client side. that's why you will see that behavior. Because without the parameters, hash of the SQL string won't change and this hash
means the cache key
. More info.client side evaluation
, you can use the saltKey parameter, to change the final hash and make it unique.ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)
to your EF Core settings to see which queries are being evaluated on the client, not on the server.Oh, thank you for links to the materials.
We use PostgresQL instead of MSSQL server.
So, to make it clear, we should use just .Where(x => x.Title == title)
to search with insensitive case in LinqToSql even title
has some kind of "pOsT1"value, isn't it?
client side evaluation
, you can use the saltKey parameter, to change the final hash and make it unique.Collation
concept.Thank you for explanation of background!
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related problems.
If we cache an expression that contains
string.Equals(string)
, a result will be the same even any kind of string value would be passed as arguments. But a waystring == string
works.