This project is read-only.


Allow ODataResult<T> to have 0 count values


The issue comes from:

The scenario is that user uses ODataResult<T> to customize next page link and inline count in action. What happens if the result collection is empty? The expected behavior is to return an empty collection with inlinecount as zero but without next page link.

The actual behavior is throwing: System.ArgumentOutOfRangeException occurred
Message=Value must be greater than or equal to 1.
Parameter name: value
Actual value was 0.
   at System.Web.Http.OData.ODataResult.set_Count(Nullable`1 value) in C:\dd\DevDiv\Offcycle\WPT\WebStackRuntime\runtime\src\System.Web.Http.OData\OData\ODataResult.cs:line 36
Closed Jan 18, 2013 at 10:03 PM by hongyes


HongmeiG wrote Nov 26, 2012 at 11:15 PM

Consider removing the ODataResult<T> now we have ResultLimit support.

HongmeiG wrote Nov 26, 2012 at 11:17 PM

Please add some code snippet to see how you can customize the next page link in the request properties bag.

Ridermansb wrote Jan 3, 2013 at 12:31 AM

But it still does not support the inlinecount!
Only with the ODataResult inlinecount is supported.

bzuidgeest wrote Jan 8, 2013 at 10:28 AM

You cannot compare odataresult<t> and resultlimit. ResultLimit is for ensure the maximum number of results that are returned. odataresult supports inlinecount, something that is used for paging and thus quite different. So please do not remove odataresult!

Also I work around this problem using null when the count is zero. It removes the problem.

public partial class CollectionsController : ApiController
        Entities entities = new Entities();

        public ODataResult<Collection> Get(ODataQueryOptions options)
            var results = (options.ApplyTo(entities.Collections) as IQueryable<Collection>);
            return new ODataResult<Collection>(results, new Uri("http://nextpage"), Request.GetInlineCount() == 0 ? null : Request.GetInlineCount());

youssefm wrote Jan 8, 2013 at 11:29 PM

youssefm wrote Jan 8, 2013 at 11:30 PM

Don't worry guys, we're not removing ODataResult<T>, just renaming it : )