[CSHARP-3497] LINQ3: Translate All and Any in filters Created: 19/Mar/21  Updated: 28/Oct/23  Resolved: 04/Oct/21

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

Type: Task Priority: Major - P3
Reporter: Robert Stam Assignee: Robert Stam
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by CSHARP-3473 LINQ3: Get PredicateTranslatorTests t... Closed
Related
related to CSHARP-4558 Support IEnumerable.TypeOf<>() in fin... Backlog
Epic Link: CSHARP-2608

 Description   

There are many scenarios. The basic ones are:

F.All(predicate) => { F : { $not : { $elemMatch : { $not : <predicate> } } } }
F.Any() => { F : { $ne : null, $not : { $size : 0 } } }
F.Any(predicate) => { F : { $elemMatch : <predicate> } } 

The following are special cases that translate to $in or $all:

a.All(i => F.Contains(i)) => { F : { $all : [<a>] } }
a.Any(i => F.Contains(i)) => { F : { $in : [<a>] } }
F.Any(i => a.Contains(i)) => { F : { $in : [<a>] } }
 
// where a is an array constant and F is an array field

All or Any may also be preceded by a Where:

F.Where(p1).All(p2) => { F : { $not : { $elemMatch : { $not : <p1 && p2> } } } }
F.Where(p1).Any() => { F : { $elemMatch : <p1> } }
F.Where(p2).Any(p2) => { F : { $elemMatch : <p1 && p2> } } 

All or Any may also be preceded by an OfType:

F.OfType<T>().All(p) => { F : { $not : { $elemMatch : { $not : { $and : [{ _t : <disc> }, <p>] } } } } }
F.OfType<T>().Any() => { F : { $elemMatch : { _t : <disc> } } }
F.OfType<T>().Any(p) => { F : { $elemMatch : { $and : [{ _t : <disc> }, <p>] } } } 

And finally, Where and OfType may both be used, possibly multiple times, in which case there are more than two predicates and the above generalizes to combine all the predicates.



 Comments   
Comment by Robert Stam [ 19/Mar/21 ]

Done but not reviewed

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