1

Closed

Allow ODataResult<T> to have 0 count values

description

The issue comes from: http://stackoverflow.com/questions/13561604/odata-result-with-an-empty-listzero-count-results-in-an-error

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
HResult=-2146233086
Message=Value must be greater than or equal to 1.
Parameter name: value
Actual value was 0.
Source=System.Web.Http.OData
ParamName=value
StackTrace:
   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
InnerException:
Closed Jan 18, 2013 at 9:03 PM by hongyes
Verified

comments

HongmeiG wrote Nov 26, 2012 at 10:15 PM

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

HongmeiG wrote Nov 26, 2012 at 10: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 2, 2013 at 11:31 PM

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

bzuidgeest wrote Jan 8, 2013 at 9:28 AM

@HongmeiG
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 10:29 PM

youssefm wrote Jan 8, 2013 at 10:30 PM

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