AspNetCoreOData icon indicating copy to clipboard operation
AspNetCoreOData copied to clipboard

Fixes #766, Support in memory filtering after ODataQueryOptions.ApplyTo

Open xuzhg opened this issue 2 years ago • 5 comments

Fixes #766.

If we have $select and $expand in the request query, the result is collection of ISelectExpandWrapper.

It's not easy for customers to do further. So Add 'Cast' Extension methods on IQueryable and Object.

Basic usage in the controller/action:

IQueryable query = options.ApplyTo(....);
IEnumerable<Customer> results = query.OCast<Customer>(query); // the new extension methods on IQueryable.

foreach (var a in results)
{
    // a is a partial object of Customer if we have $select and $expand.
}

Thanks.

xuzhg avatar Jan 26 '23 00:01 xuzhg

@julealgon Please take a look and share your thoughts.

xuzhg avatar Jan 26 '23 00:01 xuzhg

We need this. Any updates??

bogdan-patraucean avatar Oct 03 '23 11:10 bogdan-patraucean

We had a discussion on this today -- what is the expected behavior if there is a $select applied to the query on which OCast<T>() is called? should we ignore the $select and set all of the properties, or should we only set the properties that are specified in $select and leave it to the developer to somehow understand which properties have been set and which have not?

mikepizzo avatar Oct 03 '23 16:10 mikepizzo

Awesome! I would expect the select to work. I can't use the select clause with IQueryable so I have to add the needed properties in my endpoint using the Select method.

From my understanding, this PR would fix the issue.

bogdan-patraucean avatar Oct 03 '23 17:10 bogdan-patraucean

or should we only set the properties that are specified in $select

Wouldn't that clash with required properties? What if the user didn't select some properties that are marked as required in the original model? If you then try to recreate the same object but only set the selected properties, this will fail.

julealgon avatar Oct 03 '23 19:10 julealgon