0

For jquerydatatable, I need to prodive a json like this:

{
 rusults:[],
 count: 100
}.

Before actually hitting db, I have an iqueryable. Because I only get a specific number of per page, I have to use skip and take to get result (one request) and use another request to get item count for pagination.

Please tell me how could I avoid second request?

hoanvd1210
  • 149
  • 5
  • 15
  • Why do you want to avoid the second request? You're not exactly the first trying this and it is generally discouraged. – Gert Arnold Jun 16 '18 at 10:11
  • In pure TSQL you can do that. Create a soted procedure and doing [this](https://stackoverflow.com/questions/12352471/getting-total-row-count-from-offset-fetch-next) – CodeNotFound Jun 16 '18 at 10:28
  • @GertArnold: second request is relevant to count(*), which will down performance if data is really large. That is why I want to avoid it. – hoanvd1210 Jun 16 '18 at 12:26
  • @CodeNotFound: I know that it can be achieved easily by store, but I have to deal with another problem. This is I have to create every proc for every repositories. – hoanvd1210 Jun 16 '18 at 12:29
  • *which will down performance* Did you actually measure that? Databases tend to be very fast with Count queries. I've done quite a bit of research on this in the past. All alternatives are actually slower than simply executing two queries and needlessly complex. The only thing that may be worth while is executing the two queries in one batch (one roundtrip) using third-party libraries. – Gert Arnold Jun 16 '18 at 12:50

0 Answers0