(Working in VS 2010, C# 4.0, RadControls for ASP.NET AJAX 2010.2.929.40, Sql Server 2008)
When I have the following radgrid :
3 queries are generated :
and this in my codebehind :
only gives the first 2 queries of the aforementioned 3 which solves my problem.
However, I don't know why in the first case I get 3 queries instead of 2. I would expect only the 2 queries in both cases. More worrying, I can imagine forgetting (me or my colleagues) that I must declare the LinqDataSource in the aspx page and not in my codebehind and so end up querying the whole table.
When I have the following radgrid :
<telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" GridLines="None" OnNeedDataSource="RadGrid1_NeedDataSource" AutoGenerateColumns="true" AutoGenerateEditColumn="true"> </telerik:RadGrid>and this in my code behind :
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { LinqDataSource ds = new LinqDataSource(); ds.Selecting += (sd, evt) => evt.Result = new UserManager().GetAllUsers(); RadGrid1.DataSource = ds; }SELECT COUNT(*) AS [value] FROM [dbo].[Portal_Users] AS [t0] SELECT [t1].[Id], [t1].[FirstName], [t1].[LastName], [t1].[Email], [t1].[LastLogin], [t1].[Created] FROM ( SELECT ROW_NUMBER() OVER (ORDER BY [t0].[Id], [t0].[FirstName], [t0].[LastName], [t0].[Email], [t0].[LastLogin], [t0].[Created]) AS [ROW_NUMBER], [t0].[Id], [t0].[FirstName], [t0].[LastName], [t0].[Email], [t0].[LastLogin], [t0].[Created] FROM [dbo].[Portal_Users] AS [t0] ) AS [t1] WHERE [t1].[ROW_NUMBER] BETWEEN @p0 + 1 AND @p0 + @p1 ORDER BY [t1].[ROW_NUMBER] SELECT [t0].[Id], [t0].[FirstName], [t0].[LastName], [t0].[Email], [t0].[LastLogin], [t0].[Created] FROM [dbo].[Portal_Users] AS [t0]The first 2 queries are as expected but the 3rd one queries the whole users table. As this gives horrible performance with a large dataset I started digging around. Then I discovered that this :
<telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" GridLines="None" DataSourceID="linqDS" AutoGenerateColumns="true" AutoGenerateEditColumn="true"> </telerik:RadGrid> <asp:LinqDataSource ID="linqDS" OnSelecting="selecting" runat="server" />protected void selecting(object sender, LinqDataSourceSelectEventArgs e) { e.Result = new UserManager().GetAllUsers(); }However, I don't know why in the first case I get 3 queries instead of 2. I would expect only the 2 queries in both cases. More worrying, I can imagine forgetting (me or my colleagues) that I must declare the LinqDataSource in the aspx page and not in my codebehind and so end up querying the whole table.