views:

459

answers:

0

I'm passing a LinqDataSource into a Telerik RadGrid. The LinqDataSource is an LLBLGen ORM. Everything is working great - paging, grouping, filtering, etc. all work nicely.

I wanted to see how the SQL queries looked. I found these curious results:

  1. When I look at page 1, two queries are executed... 1 for the total record count and 1 for ALL records (which could be a very large dataset in this case).

  2. When I look at page 2 or higher, two queries get executed... 1 for the total record count and 1 for ONLY the records on page 2 (the TSQL equivalent of LINQ's Skip & Take).

I understand the total record count query... The grid needs that to compute total pages, etc. Furthemore, I understand (and expect) the Skip/Take settings in the query for pages 2-n.

What I don't understand is why Page 1 gets ALL records while subsquent pages limit the query result. My guess is this the manner in which the LinqDataSource is controlling the

Both the Telerik Grid and LinqDataSource are setup to enable paging.

Here's the query ouput...

Get Page 1 Rows:

N'SELECT [LPLA_1].[ID], [LPLA_1].[Item], [LPLA_1].[ChargeTo], [LPLA_1].[Sender], [LPLA_1].[Receiver], [LPLA_1].[TransactionCount] AS [Count] FROM 
[CruncherDev].[dbo].[tInboundWebFormsLine] [LPLA_1]  WHERE ( ( ( ( ( ( ( [LPLA_1].[ID_InboundFile] = @IdInboundFile1)))))))',N'@IdInboundFile1 bigint',@IdInboundFile1=133

Get Page 2 to Page n Rows:

N'CREATE TABLE #TempTable ([__rowcnt][int] IDENTITY (1,1) NOT NULL,[ID][BigInt] NULL,[Item][NVarChar](50) NULL,[ChargeTo][NVarChar](50) NULL,[Sender][NVarChar](50) 
NULL,[Receiver][NVarChar](50) NULL,[Count][NVarChar](50) NULL);INSERT INTO #TempTable ([ID],[Item],[ChargeTo],[Sender],[Receiver],[Count]) SELECT TOP 41 [LPLA_1].[ID], [LPLA_1].[Item], 
[LPLA_1].[ChargeTo], [LPLA_1].[Sender], [LPLA_1].[Receiver], [LPLA_1].[TransactionCount] AS [Count] FROM [CruncherDev].[dbo].[tInboundWebFormsLine] [LPLA_1]  WHERE ( ( ( ( ( ( ( 
[LPLA_1].[ID_InboundFile] = @IdInboundFile1)))))));SELECT [ID],[Item],[ChargeTo],[Sender],[Receiver],[Count] FROM #TempTable WHERE [__rowcnt] > @__rownoStart AND [__rowcnt] <= @__rownoEnd ORDER BY 
[__rowcnt] ASC;DROP TABLE #TempTable',N'@IdInboundFile1 bigint,@__rownoStart int,@__rownoEnd int',@IdInboundFile1=133,@__rownoStart=20,@__rownoEnd=40

Any ideas?

Thanks - Jeff