I used the following code to enter Odata style parameters into the query. This works fine until I try to use $ expand and I get an error when casting
Cannot use an object of type 'System.Data.Entity.Infrastructure.DbQuery 1[System.Web.Http.OData.Query.Expressions.SelectExpandBinder+SelectAllAndExpand 1 [STOS.Repository.Entities.Item]]' to enter 'System.Collections. Generic.IEnumerable`1 [STOS.Repository.Entities.Item].
public static List<T> ApplyTo<T>(HttpRequestMessage request, IQueryable<T> query) { var context = new ODataQueryContext(TheEdmModel(), typeof(T)); var newOptions = new ODataQueryOptions<T>(context, request); return ((IEnumerable<T>)newOptions.ApplyTo(query)).ToList(); }
I understand that when $ expand is used, another wrapper class is returned, but how can I convert it to a list?
source share