Skip to content

Commit

Permalink
Added support for $count
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmoradi committed Aug 2, 2017
1 parent 3fc400e commit 64a7871
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public override async Task OnActionExecutedAsync(HttpActionExecutedContext actio
return;

bool isSingleResult = objContent.Value is SingleResult;
bool isCountRequest = actionExecutedContext.Request.RequestUri.LocalPath?.Contains("/$count") == true;

if (isSingleResult == true)
objContent.Value = ((SingleResult)objContent.Value).Queryable;
Expand Down Expand Up @@ -107,6 +108,12 @@ public override async Task OnActionExecutedAsync(HttpActionExecutedContext actio
objContent.Value = currentOdataQueryOptions.Filter.ApplyTo(query: (IQueryable)objContent.Value, querySettings: globalODataQuerySettings);
}

if (isCountRequest == true)
{
objContent.Value = await (Task<long>)typeof(ODataEnableQueryAttribute).GetMethod(nameof(GetCountAsync)).MakeGenericMethod(queryElementType).Invoke(this, new object[] { objContent.Value, dataProviderSpecificMethodsProvider, cancellationToken });
return;
}

if (currentOdataQueryOptions.Count?.Value == true && takeCount.HasValue == true && isSingleResult == false)
{
long count = await (Task<long>)typeof(ODataEnableQueryAttribute).GetMethod(nameof(GetCountAsync)).MakeGenericMethod(queryElementType).Invoke(this, new object[] { objContent.Value, dataProviderSpecificMethodsProvider, cancellationToken });
Expand Down

0 comments on commit 64a7871

Please sign in to comment.