Possible duplicate:
Single pagination using WebApi ($ inlinecount)
Since Asp.net WebAPi almost supports odata, it is very tempting for me to make $ inlinecount work so that it plays perfectly with kendo ui (or any other). So that it returns a value in jsonp format, I implemented a new MediaFormatter (from Stackoverflow).
The problem is that in order to get the results in the count element, they need results in order to make swap work on the server side, so now I hacked the formatter to get a fake counter for work. All this works fine, and the grid is all happy, however, getting a real account is a problem, since the returned IQueryable expression already has filters / Take for it, etc.
public override Task WriteToStreamAsync(Type type, object value, Stream stream, HttpContentHeaders contentHeaders, TransportContext transportContext) { string callback; if (IsJsonpCountableRequest(out callback)) { return Task.Factory.StartNew(() => { var q = value as IQueryable<Movie>; var count = q.Count(); // this count doesnt return the actual count var writer = new StreamWriter(stream); writer.Write(callback + "({"); writer.Write(@"""d"""); writer.Write(" : { "); writer.Write(@"""results"""); writer.Write(" : "); writer.Flush(); base.WriteToStreamAsync(type, value, stream, contentHeaders, transportContext).Wait(); writer.Write(","); writer.Write(@"""__count"""); writer.Write(" : "); writer.Write(string.Format(@"""{0}""", count)); writer.Write("}"); writer.Write("})"); writer.Flush(); }); } else { return base.WriteToStreamAsync(type, value, stream, contentHeaders, transportContext); } }
Is there a way to get the counter separately, maybe from the main IQueryable provider?
np-hard
source share