-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Linq
-
None
The following LINQ expressions contain gaps in generated `$elemManch` queries.
Note: the provided expressions have wrong queries since they use `DocumentExpression` as an operand in the predicate. If the predicate operands are `FieldExpression`, the bug will not appear.
1.
Expression with bug in the generated queiry:
x => x.G.Any(g => g.E.I.Any(i => i == "insecure" || i == "igloo")) //The generated query: {G.E.I= { "$elemMatch" : { "$or" : [{ "" : "insecure" }, { "" : "igloo" }] } }}
To compare, the linq expression which doesn't generate the Mongo query with gaps:
x => x.G.Any(g => g.E.I.Any(i => i.Name == "insecure" || i.Name == "igloo")) //The generated query: {G.E.I= { "$elemMatch" : { "$or" : [{ "Name" : "insecure" }, { "Name" : "igloo" }] } }}
Pay attention on expression operands: i - DocumentExpression in the first example and i.Name - FieldExpression from the second.
2.
x => x.G.Any(g => g != null && g.E != null) //The generated query: {G= { "$elemMatch" : { "" : { "$ne" : null }, "E" : { "$ne" : null } } }}
3.
//ClassEquals: x => x.G.Any(g => g == c1 && g != c2) //where c1 and c2 are objects of some class //The generated query can be similar to: //{G= //{ "$elemMatch" : // { "" : // { // "Ids" : null, // "D" : "Dolphin", // "X" : null, // "$ne" : // { // "Ids" : null, // "D" : "Dolphin", // "X" : null // } // } // } // }}.
NOTE2: It will be a good idea to consider removing the first comparison by `Serializer` type from here.
It looks like the check on `IBsonDocumentSerializer` is problematic and not safe. This condition was the reason for the ticket CSHARP-2557.
- duplicates
-
CSHARP-2348 Search by condition with method Any (Linq) returns 0 documents when filter has OR condition
- Investigating
- related to
-
CSHARP-2557 Change in behaviour of parsing nested .Any predicates
- Closed