[CSHARP-4090] x => x.Name.Contains("FirstName", StringComparison.CurrentCultureIgnoreCase) throws NotSupportedException Created: 09/Mar/22 Updated: 28/Oct/23 Resolved: 15/Mar/22 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | LINQ3 |
| Affects Version/s: | 2.14.1 |
| Fix Version/s: | 2.15.1 |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Chock chen | Assignee: | James Kovacs |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Epic Link: | CSHARP-3615 |
| Backwards Compatibility: | Minor Change |
| Description |
|
Hi, when I trying to query LINQ request x => x.Name.Contains("FirstName", StringComparison.CurrentCultureIgnoreCase) ** throw the following error message.
Message: Expression not supported: x.Name.Contains("FirstName", CurrentCultureIgnoreCase).
Following are my using - Mongo driver: v2.14.1 ** - Linq provider: clientSettings.LinqProvider = LinqProvider.V3 NOTE: Original description described the problem that OrdinalIgnoreCase doesn't work. This is expected and explained below in the comments.
|
| Comments |
| Comment by Githook User [ 04/May/22 ] |
|
Author: {'name': 'James Kovacs', 'email': 'jkovacs@post.harvard.edu', 'username': 'JamesKovacs'}Message:
|
| Comment by Githook User [ 15/Mar/22 ] |
|
Author: {'name': 'James Kovacs', 'email': 'jkovacs@post.harvard.edu', 'username': 'JamesKovacs'}Message:
|
| Comment by chock chen [ 11/Mar/22 ] |
|
Hi, james.kovacs dmitry.lukyanov Okay! Thank you for your feedback
|
| Comment by James Kovacs [ 09/Mar/22 ] |
|
Hi, 453532579@qq.com, We have investigated the issue further and understand the root cause. A few wrinkles to mention... We currently only support StringComparison.CurrentCultureIgnoreCase. To perform case-insensitive comparisons, we use $toLower, which only has well-defined behaviour on ASCII characters. While neither StringComparison.CurrentCultureIgnoreCase nor StringComparison.OrdinalIgnoreCase quite expresses this limitation, we chose to use StringComparison.CurrentCultureIgnoreCase as StringComparison.CurrentCulture is the default in .NET. I've updated the title and description to reflect that StringComparison.CurrentCultureIgnoreCase throws a NotSupportedException when it shouldn't. We will continue to throw NotSupportedException for StringComparison.OrdinalIgnoreCase until the database supports ordinal comparisons. The next wrinkle... string.Contains(string, StringComparison) is only available starting in .NET Standard 2.1. Thus it will only work if you are targeting .NET Core 3.X, .NET 5, or .NET 6. Notably it will not work with .NET Core 2.X nor .NET Framework. Interestingly you can compile a .NET Core 2.1 app (but not 2.0) using this overload, but NuGet packages target .NET Standard, not particular runtimes, and thus cannot provide support for this overload until .NET Standard 2.1 - which requires .NET Core 3.X or later. Last wrinkle... While investigating this issue, we discovered a related issue Sincerely, |
| Comment by Dmitry Lukyanov (Inactive) [ 09/Mar/22 ] |
|
Hello 453532579@qq.com , thanks for your report, we will check it and come back to you. |