[CSHARP-4557] LINQ3 produces ExpressionNotSupported error on ContainsKey Created: 02/Mar/23  Updated: 28/Oct/23  Resolved: 17/Mar/23

Status: Closed
Project: C# Driver
Component/s: LINQ3
Affects Version/s: 2.19.0
Fix Version/s: 2.19.1

Type: Bug Priority: Unknown
Reporter: Chris Dueck Assignee: Robert Stam
Resolution: Fixed Votes: 0
Labels: LINQ, LINQ3
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

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

After upgrading from version 2.18.0 to 2.19.0, I encountered this error in my project:

{{MongoDB.Driver.Linq.ExpressionNotSupportedException: Expression not supported: x.Foo.ContainsKey("bar")
}}
After explicitly setting the LinqProvider back to V2, the error disappears.

Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

Driver version: 2.19.0

Server version: 5.0.15

How to Reproduce

For a collection of documents in this format:

{{{}}
    _id: ...,
    Foo:

{         "bar": 100,         "baz": 200     }

}
Create an IQueryable and perform the following LINQ query:
entities.Where(x => x.Foo.ContainsKey("bar"));

Additional Background

I'm not sure what else would be useful to add here, but I'm happy to provide further details if required.



 Comments   
Comment by Githook User [ 24/Mar/23 ]

Author:

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

Message: CSHARP-4557: Add support for ContainsKey in LINQ3.
Branch: v2.19.x
https://github.com/mongodb/mongo-csharp-driver/commit/4284dde38ce9f5dc7b9769d97f2d0f17633e129d

Comment by Fred Azevedo [ 23/Mar/23 ]

Thanks for the fix!

We were bit by this issue as well.

Is there a planned release date for 2.19.1?

Comment by Githook User [ 17/Mar/23 ]

Author:

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

Message: CSHARP-4557: Add support for ContainsKey in LINQ3.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/757ca5f572585c829f86da9a99914788e51e4ca0

Comment by epaulsen N/A [ 17/Mar/23 ]

Same issue here, v2.19 of Driver.

Comment by Robert Stam [ 16/Mar/23 ]

LINQ2 supported ContainsKey in filters, but not in aggregation expressions. LINQ3 will support ContainsKey in both scenarios.

Comment by Brecht Vanhaesebrouck [ 09/Mar/23 ]

I am having the same issue.

Comment by Robert Stam [ 07/Mar/23 ]

Thanks for reporting this. I will investigate further before long.

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