我有一个应用程序使用非常慢的gridview。GridView上的DataBind()慢
在为页面添加Trace=true
之后,我追踪了在哪里花费时间:在GridView上调用BindData()时。 GridView
连接到LinqDataSource
。
下面是跟踪输出:
GetContact 0.955485090710761 0.000339
DataBind 0.97438854173692 0.018903
PopulateStates 6.58986882347249 5.615480
下面是示例asp.net页面
<asp:LinqDataSource ContextTypeName="DAL.BALDataContext" TableName="loc_access_contacts"
ID="_ldsContact" runat="server" OrderBy="organisation, last_name, first_name">
</asp:LinqDataSource>
<cc1:CustomGridView ID="gvContact" runat="server" DataSourceID="_ldsContact" AutoGenerateColumns="False" Width="100%"
DataKeyNames="person_id" ForeColor="#333333" GridLines="None" AllowPaging="False"
AllowSorting="True" BorderStyle="None" ShowFooter="false" CaptionAlign="Top"
PagerStyle-HorizontalAlign="Left" HeaderStayPolicy="NotStay" SessionKey="Contact.GridView.Columns.SortSettings"
SaveKey="ContactManagementSortSettings" OnRowCommand="gvContact_RowCommand" OnSorting="gvContact_Sorting">
代码背后:
Trace.Write(" DataBind");
gvContact.DataBind();
Trace.Write(" PopulateStates");
populateStates(contact);
的LINQ数据源代码如下所示:
public System.Data.Linq.Table<loc_access_contact> loc_access_contacts
{
get
{
return this.GetTable<loc_access_contact>();
}
}
从此属性生成的SQL是规范SELECT <all fields> FROM loc_access_contact
。
而且表loc_access_contact
样子:
CREATE TABLE [dbo].[loc_access_contact](
[person_id] [int] IDENTITY(1,1) NOT NULL,
[organisation] [nvarchar](50) NULL,
[last_name] [nvarchar](50) NULL,
[first_name] [nvarchar](50) NULL,
[is_active] [tinyint] NULL,
[state_id] [char](2) NULL,
[postal_code] [nchar](4) NULL,
[town] [nvarchar](50) NOT NULL,
[phone_number] [nvarchar](20) NULL,
[mobile_number] [nvarchar](20) NULL,
[fax_number] [nvarchar](20) NULL,
[email_address] [nvarchar](255) NULL,
[street_name] [nvarchar](255) NULL,
[house_number] [nvarchar](20) NULL,
[postal_box] [nvarchar](20) NULL,
[language] [tinyint] NULL,
CONSTRAINT [PK_person] PRIMARY KEY CLUSTERED
(
[person_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
表中包含287接触。
DataBind怎么这么慢?我怎样才能进一步追踪发生了什么?
也许源文件中的某些属性评估速度慢? – gabba 2012-03-05 13:18:35
我已经添加了一些关于源代码的信息,但是我仍然不明白它为什么如此缓慢?该表目前有287个条目。 – Pierre 2012-03-05 13:30:33