❔ which of these queries is "better"? And will the second one work?
I'm trying to get the total results of the query before pagination to display it to the client. But when googling, some posts on stackoverflow said its impoossible without two separate queries. But it seems the second option is just one query? Or am i missing something in my code?
And this
4 Replies
The second option is also two queries
Both
.CountAsync()
and .ToListAsync()
resolve the query
As for which is better... might sound picky but neither, since both use .Include()
instead of a .Select()
With a select you might actually even be able to get the count and the results in the same queryI'm not sure I get it. Im supposed to eager load some of these related entities for the final query. I need them both the listing and its qualities
Yeah, you can do that with
.Select()
That also loads eagerly
Unless you're loading entities to update their related entities, don't use .Include()
, always .Select()
into a DTOWas this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.