enisn / AutoFilterer

AutoFilterer is a mini filtering framework library for dotnet. The main purpose of the library is to generate LINQ expressions for Entities over DTOs automatically. The first aim is to be compatible with Open API 3.0 Specifications
MIT License
458 stars 37 forks source link

Improvement on Collection Filters #36

Open enisn opened 2 years ago

enisn commented 2 years ago

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 property [] array [p] a property inside array [{}] entire object inside array

mehmetuken commented 2 years ago

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

candoumbe commented 1 year ago

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)

enisn commented 1 year ago

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