Im trying to write a generic PageResult
that I have added to a base controller.
[EnableQuery]
[HttpGet]
[Route(""]
public virtual PageResult<TListModel> Get(ODataQueryOptions<TListModel> options)
{
ODataQuerySettings settings = new ODataQuerySettings()
{
PageSize = 25,
};
IQueryable results = options.ApplyTo(DomainService.GetQueryable(), settings);
var items = results as IQueryable<TListModel>;
// return new PageResult<TListModel>(items, Request.ODataProperties().NextLink,DomainService.GetQueryable().Count());
return new PageResult<TListModel>(items, Request.ODataProperties().NextLink, Request.ODataProperties().TotalCount);
}
Now when I try call the api endpoint
/endpoint?$select=Title
I get an error
Value cannot be null.\ \ Parameter name: source
If I remove the ?$select=Title
I can call the api and the results are returned.
Is there something else I should be doing to enable this? The parameter name source....I have no idea what this is?
The full stacktrace
" at System.Linq.Queryable.Count[TSource](IQueryable
1 source)\ \ at Api.EndPoints.BaseController
5.Get(ODataQueryOptions1 options) in e:\\@Source\\Web\\Api\\.EndPoints\\BaseController.cs:line 62\ \ at lambda_method(Closure , Object , Object[] )\ \ at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\ \ at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\ \ at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary
2 arguments, CancellationToken cancellationToken)\ \ --- End of stack trace from previous location where exception was thrown ---\ \ at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\ \ at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\ \ at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()\ \ at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\ \ --- End of stack trace from previous location where exception was thrown ---\ \ at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\ \ at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\ \ at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult()\ \ at System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()\ \ --- End of stack trace from previous location where exception was thrown ---\ \ at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\ \ at System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()\ \ --- End of stack trace from previous location where exception was thrown ---\ \ at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\ \ at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\ \ at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()\ \ at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()\ \ --- End of stack trace from previous location where exception was thrown ---\ \ at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\ \ at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\ \ at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult()\ \ at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()\ \ --- End of stack trace from previous location where exception was thrown ---\ \ at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\ \ at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\ \ at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\ \ at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()"