-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Case Insensitive string comparison in Composite Foreign Keys #27467
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
This issue is lacking enough information for us to be able to fully understand what is happening. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate. |
I ran into the same issue, this has been a bug since ef core 2 as I could repro on it. Was running on SQL server. I suspect @Hylaean tried a case-insensitive comparer as a workaround, but IMO the join should be working without a special comparer. So basically you have a composite key where one column has a foreign key.
When you get related AB's on A for name=A, only values returned are up to be not including the row where the casing changes. The rest are ignored. IOW:
If the casing was The queries are correct, but it seems when it joins in code, it does a case-sensitive comparison (seemingly iterating till the key does not match any more and stops). @ajcvickers let me know if you need more info. |
Thanks @leppie, sorry I haven't yet come about to fix this for good. There is indeed the navigability issue, using a custom case insensitive comparer leads to EF Core not being able to generate the query when more two or more properties are needed for the join. |
Here is a blog post about this issue and perhaps more details https://qszhuan.github.io/dotnetcore/2018/10/03/dotnetcore-foreign-key-case-sensitive |
Here is the solution/workaround: https://docs.microsoft.com/en-us/ef/core/modeling/value-conversions?tabs=data-annotations#use-case-insensitive-string-keys |
Thanks. I was aware of this.
The issue now is when I inherited a database where composite keys were used
as foreign keys. Both CI strings.
Then the mapping doesn't work. EF doesn't know how to build the query in
such a case.
…On Wed, Feb 23, 2022, 07:04 Llewellyn Pritchard ***@***.***> wrote:
Here is the solution/workaround:
https://docs.microsoft.com/en-us/ef/core/modeling/value-conversions?tabs=data-annotations#use-case-insensitive-string-keys
—
Reply to this email directly, view it on GitHub
<#27467 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJ64RA5IY23NS2SOSFKUZDU4R2HDANCNFSM5OVSDPXQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Duplicate of dotnet/EntityFramework.Docs#2979 |
Setting up a value comparer is indeed the right way to work around this. |
I'm sorry @roji, my point is that I did that and setting up a value comparer leads to exception mentioned when the foreign key looks like that.
I've forked the repo trying to find a unit test I could use as inspiration to demonstrate this bug. Can you point me to one? |
@Hylaean sorry, I didn't notice your comment above. But in any case, what we're missing here is a full, runnable code sample - it's difficult to understand from the above bits and pieces exactly what's going on. Ideally you would just write a simple console program that reproduces the error; if there's a problem in your code (as opposed to in EF), this would also help you isolate it. |
Sorry @roji I hadn't time to reproduce this outside.
|
Duplicate of #27495 |
See also #27526 |
I fond an issue in a model were navigability of entities didn't work when casing changed between the target and source tables.
When a case insensitive comparer is added, it seems the inner and outer key selectors can't be translated.
Exception:
version information
EF Core version: 6.0.2
Database provider: *
Target framework: .NET 6.0
The text was updated successfully, but these errors were encountered: