[CSHARP-4665] ExpressionNotSupportedException for string.IsNullOrWhitespace after upgrade Created: 02/Jun/23  Updated: 28/Jun/23  Resolved: 28/Jun/23

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

Type: New Feature Priority: Unknown
Reporter: John Staveley Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on CSHARP-4683 Rename Linq3ImplementationTests folde... Closed
Documentation Changes: Not Needed
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

Summary

I am running MongoDb 6.0.6

When upgrading from Mongodbdriver 2.18 to 2.19.2 several queries I run begin to fail with the ExpressionNotSupportedException.

How to Reproduce

 
Query on any string field e.g
 
_profileDataCollection.Find(model.GetFilter())
.Project(x => new ProfileReportModel {
Id = x.Id,
Bio = !string.IsNullOrWhiteSpace(x.Bio),
CurrentStatus = !string.IsNullOrWhiteSpace(x.CurrentStatus)
 
In this example Bio and CurrentStatus are string fields
 
Downgrading the connection to LinqProvider.V2 fixes the issue:
 
var clientSettings = MongoClientSettings.FromConnectionString(Configuration.GetConnectionString(nameof(StudentProfile)));
clientSettings.LinqProvider = LinqProvider.V2;
var client = new MongoClient(clientSettings);

It appears to be similar to this issue:
https://www.mongodb.com/community/forums/t/issue-with-2-18-to-2-19-nuget-upgrade-of-mongodb-c-driver/211894
 



 Comments   
Comment by Githook User [ 28/Jun/23 ]

Author:

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

Message: CSHARP-4665: Add LINQ3 support for IsNullOrWhiteSpace.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/5974753edd6f61f391257b818469128c7f08cd51

Comment by Robert Stam [ 21/Jun/23 ]

CSHARP-4683 is justified for its own reasons, but for this issue we depend on it because CSHARP-4683 shortens paths just enough to keep the new file paths in this PR below the 260 limit imposed by Windows.

Comment by Robert Stam [ 06/Jun/23 ]

I've added support in LINQ3 for IsNullOrWhiteSpace.

Note that in the case of a Find projection, this only worked in LINQ2 because LINQ2 would sometimes execute things it couldn't translate to MQL client-side. In this case LINQ2 would fetch the values from the server and compute the IsNullOrWhiteSpace result client-side.

Other than that, LINQ2 had no support for IsNullOrWhiteSpace.

LINQ3 never executes anything client-side. This is a deliberate design decision that we made. With this fix, when using LINQ3 these types of projections will now work as long as you are using version 4.4 or newer of the server (that was the version that added support for $project style projections with expressions for find).

Comment by PM Bot [ 02/Jun/23 ]

Hi john.staveley@myglobalbridge.com, thank you for reporting this issue! The team will look into it and get back to you soon.

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