Select count (*) query before paging in DataGrid

Hello!
In the debug output window, you can see that before each data call, a request is made for the number of all records in the table.
Why is this request needed?

info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT COUNT(*)
FROM crm AS c
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (0ms) [Parameters=[@__p_0='10'], CommandType='Text', CommandTimeout='30']
SELECT c.Id, c.MatrixTypeId, c.Name
FROM crm AS c
ORDER BY (SELECT 1)
LIMIT @__p_0 OFFSET @__p_0
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT COUNT(*)
FROM crm AS c
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (1ms) [Parameters=[@__p_1='10', @__p_0='20'], CommandType='Text', CommandTimeout='30']
SELECT c.Id, c.MatrixTypeId, c.Name
FROM crm AS c
ORDER BY (SELECT 1)
LIMIT @__p_1 OFFSET @__p_0

This is needed for paging. You cannot have proper paging if you do not know total records count.

1 Like