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

Array search filters on an empty array break queries with CombineWith.Or #67

Closed Edicatax closed 1 year ago

Edicatax commented 1 year ago

Since the ArraySearchFilterAttribute by default returns Expression.Constant(true) if the array is empty or not passed, an OR query that has other filter criteria will always return everything as the resulting expression becomes something like:

x => (True OrElse (x.DateCreated >= 7/9/2023 2:20:07 PM)

This obviously is always simply true and so as long as the array attribute exists and is not passed other criteria are effectively ignored. Notably AND queries work as normal with this implementation since it is just one of many expressions that should evaluate to true.

We have solved this issue for ourselves by creating an attribute that inherits from ArraySearchFilterAttribute that simply returns null if the array is empty, which seems to fix it for OR as well as AND queries.

How is the ArraySearchFilterAttribute supposed to work, is this described functionality correct? If not, I can open a quick PR to apply our fix to the ArraySearchFilterAttribute for inclusion in a future release.

enisn commented 1 year ago

Can you specify a small object and entity object to help me to reproduce the issue? Or maybe you can add a test case to here and I can work on it

Edicatax commented 1 year ago

I have reproduced our (failing) case in the tests for AutoFilterer locally and it's passing with flying colours, so I suspect I've missed something odd in our setup that is messing with how the filters are generated :upside_down_face: . I'll dig a bit deeper but I now strongly suspect the error is on our side. I'll open a new issue if I do find something wrong.