Open enisn opened 2 years ago
https://stackoverflow.com/a/41470943 this answer may help Collection of Complex Type.
I did something similar with DataFilters
and I ended up emitting the suitable Expression<Func<T, bool>>
inside a Enumerable.Any
when the targeted property is a collection (https://github.com/candoumbe/DataFilters/blob/2c826c80ed6c0a165a16181af8189eae6aadff13/src/Datafilters.Expressions/FilterExtensions.cs#L297)
I did something similar with
DataFilters
and I ended up emitting the suitableExpression<Func<T, bool>>
inside aEnumerable.Any
when the targeted property is a collection (https://github.com/candoumbe/DataFilters/blob/2c826c80ed6c0a165a16181af8189eae6aadff13/src/Datafilters.Expressions/FilterExtensions.cs#L297)
It seems quite well,
Any & Contains are working well currently. The topic is about running all nested like All(Any(x => x)) or even much deeper All(Any(All(Contains())))
. It will go deeper according to the nested filter objects. I'll check your repository, and if it does it exactly and compatible, I can refer to your project in the documentation for this purpose instead re-inventing the wheel
See the origin of this issue: https://github.com/enisn/AutoFilterer/discussions/35
Possible Scenarios
There are 6 possibilities while generating filters for collections. 2 of them are already covered by AutoFilterer currently. Those possibilities depend on Property types of Filter and Source Objects. When a Filter object property is a collection, the query must be generated with Contains method. But there is more a couple of possibilities:
p
=>[]
[]
=>{}
[p]
=>[p]
(Contains
method insideAny/All
method. For MongoDb models)[{}]
=>[{}]
( Built Expression ({} => {}
) insideAll/Any
methodto understand how to generate query.)p
property[]
array[p]
a property inside array[{}]
entire object inside array