[CSHARP-3865] ToUpperInvariant Not Supported Created: 17/Sep/21  Updated: 28/Oct/23  Resolved: 07/Oct/21

Status: Closed
Project: C# Driver
Component/s: Linq
Affects Version/s: None
Fix Version/s: 2.14.0

Type: Bug Priority: Unknown
Reporter: Richard Collette Assignee: Robert Stam
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to CSHARP-4121 Review ToLower and ToUpper uses of Cu... Backlog
Epic Link: CSHARP-3615

 Description   

The documentation states that ToUpperInvariant is supported but I am getting an error when using it.

{
  "invalid-operation": [
    "{document}{friendlyName}.ToUpperInvariant() is not supported."
  ]
}



 Comments   
Comment by Robert Stam [ 01/Apr/22 ]

We now think it was a mistake to implement this.

The implementation treats ToLowerInvariant and ToUpperInvariant as synonyms for ToLower and ToUpper, but that's not actually correct.

The server has no support for doing culture-invariant to upper or lower case transformations, so it's a mistake to claim to support these methods.

Comment by Robert Stam [ 07/Oct/21 ]

This issue has been fixed in the new LINQ provider (known as LINQ3) which will be included in the upcoming 2.14 release.

Configure your MongoClientSettings to use LinqProvider.V3 if you want to use this functionality.

To configure a client to use the LINQ3 provider use code like the following

var connectionString = "mongodb://localhost";
var clientSettings = MongoClientSettings.FromConnectionString(connectionString);
clientSettings.LinqProvider = LinqProvider.V3;
var client = new MongoClient(clientSettings);

Comment by Richard Collette [ 07/Oct/21 ]

Thank you!

Comment by Githook User [ 07/Oct/21 ]

Author:

{'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}

Message: CSHARP-3865: LINQ3: Support ToLowerInvariant and ToUpperInvariant.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/5276c39b23804d17646c69310ec0825946c98a5c

Comment by Robert Stam [ 22/Sep/21 ]

With a few minor changes `ToLowerInvariant` and `ToUpperInvariant` now work in the new LINQ implementation.

Also, it works in combination with either `==` or `Equals`.

Comment by Dmitry Lukyanov (Inactive) [ 21/Sep/21 ]

Hey richard.collette@gmail.com,

thanks for your report, you're right that the c# "equal" operator works a bit different than the "Equals" method. Since there is a workaround with "=" operator, we're going to address this issue in the next LINQ implementation which is currently in code review.

Comment by Richard Collette [ 17/Sep/21 ]

The same issue presents when using ToUpper().Equals() in a FindAsync operation.  It works only if you do ToUpper() == .

Comment by Richard Collette [ 17/Sep/21 ]

ToLowerInvariant does not work either.  This may be specific to linq queries.

public Product? GetProductByFriendlyName(string friendlyName)
{
    return
        (from product in _products.AsQueryable()
            // Note that .Equals(value,StringComparison) is not supported.
            where product.FriendlyName.ToUpper().Equals(friendlyName.ToUpper())
            select product).SingleOrDefault();
} 

Generated at Wed Feb 07 21:46:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.