-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 2.8.0, 2.8.1, 2.9.0, 2.9.1, 2.10.0
-
Component/s: Builders, Linq, Serialization
-
None
Since 2.8.0, translation of LINQ query has broken for me - I now get a NotSupportedException, where before the query translated fine. The query I want is as below:
{ "$or": [ { "Invitees.Organisers": { "$in": [ "Bob", "John", "Tim", "Ryan" ] } }, { "Invitees.Roles": { "$elemMatch": { "k": { "$in": [ "Bob", "John", "Tim", "Ryan" ] }, "v": { "$in": [ "party_planning", "food_preparation" ] } } }, "Invitees.BlacklistRoles": { "$not": { "$elemMatch": { "k": { "$in": [ "Bob", "John", "Tim", "Ryan" ] }, "v": { "$in": [ "party_planning", "food_preparation" ] } } } } } ] }
To achieve this I use the following link query:
x => x.Invitees.Organisers.Any(a => invitees.Contains(a)) || ( x.Invitees.Roles.Any(y => invitees.Contains(y.Key) && roles.Any(r => y.Value.Contains(r))) && !(x.Invitees.BlacklistRoles.Any(y => invitees.Contains(y.Key) && roles.Any(r => y.Value.Contains(r)))) )
The full exception I receive is:
System.NotSupportedException: The LINQ expression: {Invitees.Roles}.Where((Contains(value(System.Collections.Generic.List`1[System.String])) AndAlso All(value(System.Collections.Generic.HashSet`1[System.String]).Where(Contains({document}{v}))))) has the member "y" which can not be used to build a correct MongoDB query.
- is related to
-
CSHARP-2786 Investigate correctness of generated mongo queries with `Project` linq
- Closed