AutoFilterer icon indicating copy to clipboard operation
AutoFilterer copied to clipboard

Improvement on Collection Filters

Open enisn opened this issue 4 years ago • 3 comments
trafficstars

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 inside Any/All method. For MongoDb models)
  • [ ] [{}]=> [{}] ( Built Expression ({} => {}) inside All/Any methodto understand how to generate query.)

p property [] array [p] a property inside array [{}] entire object inside array

enisn avatar Oct 18 '21 10:10 enisn

https://stackoverflow.com/a/41470943 this answer may help Collection of Complex Type.

mehmetuken avatar Feb 02 '22 11:02 mehmetuken

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)

candoumbe avatar Jun 27 '23 08:06 candoumbe

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)

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

enisn avatar Jul 04 '23 05:07 enisn