I have implemented OData for querying the list generated by my API. But some times the list is empty and the OData Result should just return an empty json but it doesnt. Instead it throws up the following error
Value must be greater than or equal to 1. Parameter name: value Actual value was 0.
This is my controller method
// Get states by Id
[HttpGet]
[ActionName("GetStatesByID")]
public ODataResult<DataAccess.Model.State> GetStatesByID(ODataQueryOptions options,int id)
{
var states = this.Repository.GetAllStatesByCountry(id).AsQueryable<DataAccess.Model.State>();
var results = (options.ApplyTo(states) as IQueryable<DataAccess.Model.State>);
long count = states.Count();
return new ODataResult<DataAccess.Model.State>(results, null, count);
}
I can put the count as 0 whenever the list is empty and that will not throw an error but that really is not a good practice, so i wanted to know if there is any other work around for this so that ODataResult returns an empty json when the list is empty rather than throwing up an error?
Thanks