Datagrid sub properties column filter fails for IQueryable on DBContext #1945

Closed
opened 2026-01-29 18:15:57 +00:00 by claunia · 5 comments
Owner

Originally created by @RaHorusFreak on GitHub (Jan 9, 2026).

Describe the bug
When implementing the example case: "DataGrid Sub Properties Column Filter", the arguments produced for "LoadDataArgs.Filter" cause errors when used via OData againts a DBContext.

Additional context
All related info is in https://github.com/radzenhq/radzen-blazor/issues/2396. This happens when using the filter produced by LoadDataArgs.Filter via System.Linq.Dynamic.Core extension methods for IQueryable over a DBContext + EF Core. The original issue was marked as closed without a any solution.

Originally created by @RaHorusFreak on GitHub (Jan 9, 2026). **Describe the bug** When implementing the example case: "DataGrid Sub Properties Column Filter", the arguments produced for "LoadDataArgs.Filter" cause errors when used via OData againts a DBContext. **Additional context** All related info is in https://github.com/radzenhq/radzen-blazor/issues/2396. This happens when using the filter produced by LoadDataArgs.Filter via System.Linq.Dynamic.Core extension methods for IQueryable over a DBContext + EF Core. The original issue was marked as closed without a any solution.
Author
Owner

@enchev commented on GitHub (Jan 9, 2026):

Have you used ODataEnumerable as I advised? Please provide runnable code demonstrating the problem.

@enchev commented on GitHub (Jan 9, 2026): Have you used ODataEnumerable as I advised? Please provide runnable code demonstrating the problem.
Author
Owner

@RaHorusFreak commented on GitHub (Jan 12, 2026):

Hello @enchev, thanks for your reply.

In my project, everything works, including the filters and pagination against a db context via EF Core. The problem arises when I try to implement "DataGrid Sub Properties Column Filter" (https://blazor.radzen.com/datagrid-sub-properties-filter) against a DbSet via System.Linq.Dynamic.Core over an IQueryable. In a nutshell, the filter provided by LoadDataArgs.Filter (that works on an IEnumerable) fails against an IQueryable due to syntax errors:

x => x.Collection.Any(x => ((x ?? "").ToLower() ?? "").Contains("test"))

This is a snippet of the filter generated when I try to filter against a column that has a collection of type string. As you can see, the variable x is declared twice, which causes the error: System.Linq.Dynamic.Core.Exceptions.ParseException: '')' or ',' expected'. Hence, it is impossible to apply OData on a collection-type column in a DbSet or on a collection-type projection using LoadDataArgs.Filter.

In my case, I was able to get it to work correctly by detecting and replacing the segment in the filter with:

x => x.Collection.Any(x1 => ((x1 ?? "").ToLower() ?? "").Contains("test"))

where instead of declaring 2 x vars, I use x and x1. For the remaining cases, LoadDataArgs.Filter fits perfectly with a db context.

@RaHorusFreak commented on GitHub (Jan 12, 2026): Hello @enchev, thanks for your reply. In my project, everything works, including the filters and pagination against a db context via EF Core. The problem arises when I try to implement "DataGrid Sub Properties Column Filter" (https://blazor.radzen.com/datagrid-sub-properties-filter) against a `DbSet` via `System.Linq.Dynamic.Core` over an `IQueryable`. In a nutshell, the filter provided by `LoadDataArgs.Filter` (that works on an `IEnumerable`) fails against an `IQueryable `due to syntax errors: `x => x.Collection.Any(x => ((x ?? "").ToLower() ?? "").Contains("test"))` This is a snippet of the filter generated when I try to filter against a column that has a collection of type string. As you can see, the variable `x` is declared twice, which causes the error: `System.Linq.Dynamic.Core.Exceptions.ParseException: '')' or ',' expected'`. Hence, it is impossible to apply `OData` on a collection-type column in a `DbSet` or on a collection-type projection using `LoadDataArgs.Filter`. In my case, I was able to get it to work correctly by detecting and replacing the segment in the filter with: `x => x.Collection.Any(x1 => ((x1 ?? "").ToLower() ?? "").Contains("test"))` where instead of declaring 2 `x` vars, I use `x` and `x1`. For the remaining cases, `LoadDataArgs.Filter` fits perfectly with a db context.
Author
Owner

@enchev commented on GitHub (Jan 12, 2026):

Again - use ODataEnumerable. This is what tells the DataGrid to use OData expressions.

@enchev commented on GitHub (Jan 12, 2026): Again - use ODataEnumerable. This is what tells the DataGrid to use OData expressions.
Author
Owner

@RaHorusFreak commented on GitHub (Jan 12, 2026):

I'm sorry for not expressing myself correctly: my goal is not to use OData properly, but rather to be able to evaluate the dynamic query produced by LoadDataArgs.Filter on an IQueryable, so in order to establish greater clarity on the subject, I will change the title of the issue.

In my workflow, I take LoadDataArgs.Filter (as it is) and use it as a dynamic where clause for a DbSet via System.Linq.Dynamic.Core, and that is why I need the query in its original format, and not in OData format. So basically what I do is apply the filter produced by LoadDataArgs.Filter to a db context. That is why I get a syntax error when trying to filter by a subproperty (it works perfectly for the other columns).

I am implementing something like this: https://blazor.radzen.com/datagrid-loaddata?theme=material3-dark

void LoadData(LoadDataArgs args)
{
    var query = dbContext.Employees.AsQueryable();
    if (!string.IsNullOrEmpty(args.Filter))
    {
        query = query.Where(args.Filter);
    }
    if (!string.IsNullOrEmpty(args.OrderBy))
    {
        query = query.OrderBy(args.OrderBy);
    }
    count = query.Count();
    employees = query.Skip(args.Skip.Value).Take(args.Top.Value).ToList();
}

I tried implementing what you sugested without a RadzenDataFilter, but what happened to me was that when trying to filter a subproperty, LoadDataArgs.Filter was empty, and it is not possible for me to expose my db context through an endpoint like [EnableQuery].

The issue here lies in the declaration of variables used when constructing the filter, where duplicate variables lead to an error on the part of System.Linq.Dynamic.Core. So basically, the workaround I have implemented looks for the main variable of the filter (x), and any additional declaration of it within ["Any", "All", "Count"] is replaced with a random name, changing the value of LoadDataArgs.Filter from x => x.Collection.Any(x => ((x ?? "").ToLower() ?? "").Contains("test")) to x => x.Collection.Any(x1 => ((x1 ?? "").ToLower() ?? "").Contains("test")).

@RaHorusFreak commented on GitHub (Jan 12, 2026): I'm sorry for not expressing myself correctly: my goal is not to use `OData` properly, but rather to be able to evaluate the dynamic query produced by `LoadDataArgs.Filter` on an `IQueryable`, so in order to establish greater clarity on the subject, I will change the title of the issue. In my workflow, I take `LoadDataArgs.Filter` (as it is) and use it as a dynamic `where` clause for a `DbSet` via `System.Linq.Dynamic.Core`, and that is why I need the query in its original format, and not in `OData` format. So basically what I do is apply the filter produced by `LoadDataArgs.Filter` to a db context. That is why I get a syntax error when trying to filter by a subproperty (it works perfectly for the other columns). I am implementing something like this: https://blazor.radzen.com/datagrid-loaddata?theme=material3-dark ``` void LoadData(LoadDataArgs args) { var query = dbContext.Employees.AsQueryable(); if (!string.IsNullOrEmpty(args.Filter)) { query = query.Where(args.Filter); } if (!string.IsNullOrEmpty(args.OrderBy)) { query = query.OrderBy(args.OrderBy); } count = query.Count(); employees = query.Skip(args.Skip.Value).Take(args.Top.Value).ToList(); } ``` I tried implementing what you sugested without a `RadzenDataFilter`, but what happened to me was that **when trying to filter a subproperty, `LoadDataArgs.Filter` was empty**, and it is not possible for me to expose my db context through an endpoint like `[EnableQuery]`. The issue here lies in the declaration of variables used when constructing the filter, where duplicate variables lead to an error on the part of `System.Linq.Dynamic.Core`. So basically, the workaround I have implemented looks for the main variable of the filter (x), and any additional declaration of it within `["Any", "All", "Count"]` is replaced with a random name, changing the value of `LoadDataArgs.Filter` from `x => x.Collection.Any(x => ((x ?? "").ToLower() ?? "").Contains("test"))` to `x => x.Collection.Any(x1 => ((x1 ?? "").ToLower() ?? "").Contains("test"))`.
Author
Owner

@enchev commented on GitHub (Jan 12, 2026):

System.Linq.Dynamic.Core lyrabray is no longer supported (since v.6.0). We have substitude methods in the same namespace that can parse valid C# lamda from string.

@enchev commented on GitHub (Jan 12, 2026): System.Linq.Dynamic.Core lyrabray is no longer supported (since v.6.0). We have substitude methods in the same namespace that can parse valid C# lamda from string.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#1945