Can you get an IQueryable and its results from its string representation?

579 Views Asked by At

I've started a Blazor Web Assembly Project that makes use of Radzen components. I'm trying to create a search through my API, and I would like to use a combination of their DataGrid and new DataFilter components to do so. It looks like the best way I can do this is by tapping into the DataFilter's ViewChanged event callback, within which I can access an IQueryable.

So if I were to filter Person data by name and print out the resultant IQueryable in this callback, I get something like this:

TheMill.Shared.Models.Mill.Person[].Where(Param_0 => (IIF((Param_0.DisplayName1 == null), "", Param_0.DisplayName1) == "Ben"))

Is it possible to send this string to my API endpoint, run the query, and return the Person records that match? I'm hoping I'm headed in the right direction by looking into the ParseLambda function from Dynamic LINQ.

1

There are 1 best solutions below

0
StriplingWarrior On

The approach you're describing is fraught. The .ToString() representation of IQueryables is not designed to be parsed back into a query. It is not guaranteed to contain all the information you need in your query (for example, if you use a closed-over variable in your your lambda instead of a hard-coded string), and it can change from one version of .NET Framework to the next.

Instead, I'd recommend looking into something like OData, which is a standards-based way of creating a query string that can be translated into an Entity Framework query. In fact, Radzen's Blazor DataGrid natively supports OData bindings.