C#C
C#2y ago
nox7

EF Core - Runtime-Based "OR" "AND" Comparison in Where()

I am allowing users on a web application to create filters on a queried table. It will generate an array of "filters" in defined order. They will be able to define if the next comparison is connected to the previous via "OR" or "AND"

On the back-end, I will iterate over each "Filter" in the array of filters, adding more .Where() calls to the IQueryable. However, how can I make create an IQueryable that can properly chain these filters so that they are concatenated by "OR" or "AND" appropriately from the previous filter?

E.g.
User submits two filters for two columns. They could be linked as Column1 = "ss" OR Column2 = "DD"

Or they could submit it as Column1 = "ss" AND Column2 = "DD"
Was this page helpful?