I'm stumped on this performance issue. When paging a RadGrid I get instantaneous results. However, when I filter any of the columns, the query takes around 10 seconds to complete and any paging applied after the filter remains just as slow. If I remove the filter the performance is just fine.
Production is a SharePoint 2010 Server which is hosted in-house with a small number of users. I am using a RadGrid control, version 2009.3..1314.35 that queries a table containing 30,000 records. I am using LINQ to SQL for the back-end. I have used IE and Firefox in production. On my development machine there are no performance issues.
The query isn't complex, the record source isn't exceptionally large and the traffic is low, so I'm not sure how to track the issue down. Here are some thoughts I have:
- Something is wrong with my LINQ query.
- Misuse or misunderstanding of the RadGrid.
- Database isn't optimized? I converted it from Access to SQL Server 2008.
- Network issue?
Below is my code. Any help would be appreciated.
ASPX:
<telerik:GridTemplateColumn AllowFiltering="false" SortExpression="Marked" HeaderText="Marked" UniqueName="Marked">
<ItemTemplate>
<asp:CheckBox
ID="chkbxMarked" runat="server"
OnCheckedChanged="ToggleRowSelection"
Checked='<%# Eval("Marked") %>'
AutoPostBack="True" />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="NamePrefix" SortExpression="NamePrefix" Allo开发者_如何学GowFiltering="false" HeaderText="Name Prefix" />
<telerik:GridBoundColumn DataField="LastName" SortExpression="LastName" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" HeaderText="Last Name" />
<telerik:GridBoundColumn DataField="FirstName" SortExpression="FirstName" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" HeaderText="First Name" />
<telerik:GridBoundColumn DataField="MiddleName" SortExpression="MiddleName" AllowFiltering="false" HeaderText="Middle Name" />
<telerik:GridBoundColumn DataField="Phone1" SortExpression="Phone1" AllowFiltering="false" HeaderText="Phone" />
<telerik:GridBoundColumn DataField="Phone1Ext" SortExpression="Phone1Ext" AllowFiltering="false" HeaderText="Ext." />
<telerik:GridBoundColumn DataField="Email1" SortExpression="Email1" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" HeaderText="Email" />
<telerik:GridBoundColumn DataField="Profile" SortExpression="Profile" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" HeaderText="Profile" />
</Columns>
</MasterTableView>
BLL:
public IList<Person> FindAllByProfile(string profileName, int rowStart, int numRows)
{
return profileName == "All" ? _repos.FindAll(rowStart, numRows) : _repos.FindAllByProfile(profileName, rowStart, numRows);
}
public int FindAllByProfileCount(string profileName)
{
return profileName == "All" ? _repos.FindAllCount() : _repos.FindAllByProfileCount(profileName);
}
Repository:
public IList<Person> FindAll(int rowStart, int numRows)
{
using (PRADbDataContext db = new PRADbDataContext())
{
var data = from p in db.persons
join c in db.contacts on p.PersKey equals c.PersKey into personContacts
from pc in personContacts.DefaultIfEmpty()
orderby p.Modified descending
select new Person()
{
Id = p.PersKey,
AddressId = p.AddrKey,
DateModified = p.Modified,
Email1 = p.EMail1,
Marked = p.Marked,
Phone1 = p.Phone1,
Phone1Ext = p.PhExt1,
NamePrefix = p.MrMs,
FirstName = p.FName,
LastName = p.LName,
MiddleName = p.MName,
Title = p.Title,
Profile = pc.ProfKey ?? "N/A"
};
return data.Skip(rowStart).Take(numRows).ToList();
}
}
public int FindAllCount()
{
using (PRADbDataContext db = new PRADbDataContext())
{
var data = from p in db.persons
join c in db.contacts on p.PersKey equals c.PersKey
select new Person()
{
Id = p.PersKey,
};
return data.Count();
}
}
I'd recommend using LINQPad to emulate the queries.
- You can look at the SQL tab to see all the SQL being produced. If it's the SQL itself causing the problem, you can profile it in SQL Server Management Studio and see why it's taking so long.
- You can load your DLL and run your actual methods, to see if it's something to do with the way the method is handling the data.
- If you can tell that your method runs without a problem, then you can narrow down the issue to the way the telerik controls are calling your methods.
精彩评论