Datagrid Advanced Filter + Entity Framework Core

Could you please give me guidance on how to work with advanced filtering in EFCore? I'm using Radzen Blazor Components in WebAssembly client web and I'm sending whole LoadDataArgs to the server.

Paging, and sorting is relatively easy, but I'm not sure I'm doing filtering right. As Far I can tell, only thing I can do, is to iterate through Filters and it's FilterDescriptor objects and then, for every model Property property switch over all FilterOperator property variants and do specific .Where(...) variant over query.

Problem is, model properties don't have to match table model names or even exist as column in db, because they are computed (for example count of some sub-table, like main model is Company and one of the properties is Employees count, which is computed as Count() of rows of Emploee of said Company). And not all operators are applicable to all model properties, like StartsWith with numbers for example.

I noticed, that next to IEnumerable, there is string Filter property, which is formatted in some strange format / language, which kind of looks like C# but is not?

What I'm looking for are best practices how to work with LoadDataArgs class...

It is an expression that Dynamic Linq can use. Other than that it is up to you how to implement filtering based on the provided filter descriptors.

Interesting, thanks, I'll look into DynamicLinq then...

I normlay project the query to an IQueryibal then do my filter if it has computed colums or use a view if prefomance is a issue.

As long as your filter property matches your projection the LoadData model will work

1 Like