I have a WebApi controleller, and added the filters from BreezeJs to support queryable requests like $orderby=DateAdded&$top=8.
GlobalConfiguration.Configuration.Filters.Add(
new Breeze.WebApi.ODataActionFilter());
everything works fine. This only give 8 results. What do i need to do to add such the total count is also returned with the result?
UPDATE
public class ODataHandler : DelegatingHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
return base.SendAsync(request, cancellationToken).ContinueWith(
task =>
{
var response = task.Result;
if (ResponseIsValid(response) && ShouldInlineCount(request))
{
object responseObject;
response.TryGetContentValue(out responseObject);
if (responseObject is IQueryable)
{
var renum = responseObject as IEnumerable<object>;
if (renum != null)
{
response = request.CreateResponse(HttpStatusCode.OK, new ODataMetadata<object>(renum, renum.Count()));
}
}
}
return response;
});
}
private bool ShouldInlineCount(HttpRequestMessage request)
{
var queryParams = request.RequestUri.ParseQueryString();
var inlinecount = queryParams["$inlinecount"];
return string.Compare(inlinecount, "allpages", true) == 0;
}
private bool ResponseIsValid(HttpResponseMessage response)
{
if (response == null || response.StatusCode != HttpStatusCode.OK || !(response.Content is ObjectContent)) return false;
return true;
}
}
This is what i came up with so far. But problem is that the filter have already added teh TOP 8 to the request before the handler kicks in. So count will be 8 and not total.
Excellent question. The OData support in the current version of Breeze does not understand the $inlinecount parameter for OData 2.0 which, I think, is what you are looking for. It is on the backlog. Please vote up that idea on the Breeze user voice.