[CSHARP-2006] Query Lambdas: "!externalList.Contains(prop)" supported, but "externalList.Contains(prop) == false" fails Created: 21/Jun/17  Updated: 28/Oct/23  Resolved: 09/Feb/22

Status: Closed
Project: C# Driver
Component/s: Linq, LINQ3
Affects Version/s: 2.4.3
Fix Version/s: 2.14.0

Type: Bug Priority: Major - P3
Reporter: Kevin Versfeld Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: triaged
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Epic Link: CSHARP-3615

 Description   

Hey chaps
I logged a VERY similar issue some time back (which has been resolved: CSHARP-1543 )
This is specific to using the .Contains() linq extension on (in my case) a generic List, checking if it contains a property of the queried document.
Pseudo example:

var myList = new List<string>() { "bob", "frank" };
var results = queryable.Where(doc => myList.Contains(doc.prop) == false).ToList(); //this fails
var results2 = queryable.Where(doc => !myList.Contains(doc.prop)).ToList(); //this works



 Comments   
Comment by James Kovacs [ 09/Feb/22 ]

This issue has been fixed in the new LINQ provider (known as LINQ3), which is included in the 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);

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