I have been using the following code to inject "Odata" style parameters into a query. This works fine until I try to using $expand, and I get a casting error
Unable to cast object of type 'System.Data.Entity.Infrastructure.DbQuery1[System.Web.Http.OData.Query.Expressions.SelectExpandBinder+SelectAllAndExpand
1[STOS.Repository.Entities.Item]]' to type '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, a different wrapper class is returned, but how do I convert this to a List?