当使用Nhibernate从数据库表中获取大量数据时,如何加载RadGrid
我喜欢在浏览器中运行Default.aspx时减少加载时间,因为它从数据库中的表中获取大量数据当使用Nhibernate从数据库表中获取大量数据时,如何加载RadGrid,nhibernate,radgrid,icriteria,Nhibernate,Radgrid,Icriteria,我喜欢在浏览器中运行Default.aspx时减少加载时间,因为它从数据库中的表中获取大量数据 <class name="Ttable1" table="Ttable1" lazy="false" mutable="true"> <cache usage="read-only"/> <id name="ID" column="ID" > </id> <property name="CustNumber" column=
<class name="Ttable1" table="Ttable1" lazy="false" mutable="true">
<cache usage="read-only"/>
<id name="ID" column="ID" >
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
</hibernate-mapping>
当我使用criteria.SetMaxResults(200)时,网格仅加载200个数据,但我应该从数据库的表中加载RadGrid中的所有数据。当我使用criteria.SetFetchSize(200)时,加载也需要很长时间。有人能帮我找到解决方案吗
<class name="Ttable1" table="Ttable1" lazy="false" mutable="true">
<cache usage="read-only"/>
<id name="ID" column="ID" >
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
</hibernate-mapping>
这是密码
ICriteria criteria = session.CreateCriteria(typeof(Ttable1));
criteria.SetMaxResults(200);
IList result = criteria.List();
if (result.Count > 0)
{
grid1.DataSource = result;
grid1.DataBind();
}
else
{
grid1.DataSource = new string[] { };
grid1.DataBind();
}
<class name="Ttable1" table="Ttable1" lazy="false" mutable="true">
<cache usage="read-only"/>
<id name="ID" column="ID" >
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
</hibernate-mapping>
这里是地图
<class name="Ttable1" table="Ttable1" lazy="false" mutable="true">
<cache usage="read-only"/>
<id name="ID" column="ID" >
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
</hibernate-mapping>
从你给我们的东西中分辨出什么是错的是不可能的。我们不知道您的映射,表有多少列,什么都不知道
<class name="Ttable1" table="Ttable1" lazy="false" mutable="true">
<cache usage="read-only"/>
<id name="ID" column="ID" >
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
</hibernate-mapping>
问题可能由以下原因引起:
<class name="Ttable1" table="Ttable1" lazy="false" mutable="true">
<cache usage="read-only"/>
<id name="ID" column="ID" >
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
</hibernate-mapping>
- N+1选择,因为您的所有关联都是渴望的
- 数据库中有一些列包含大量数据(可能是一些附件或其他内容)
<class name="Ttable1" table="Ttable1" lazy="false" mutable="true">
<cache usage="read-only"/>
<id name="ID" column="ID" >
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
</hibernate-mapping>
您必须调试NHibernate查询并查看发生了什么。您可以通过使用show_sql、使用一些日志记录器记录日志、或使用一些探查器(如NHProf)甚至sql探查器来实现这一点
<class name="Ttable1" table="Ttable1" lazy="false" mutable="true">
<cache usage="read-only"/>
<id name="ID" column="ID" >
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
</hibernate-mapping>
您可能会看到执行了许多查询,因为没有启用延迟加载
<class name="Ttable1" table="Ttable1" lazy="false" mutable="true">
<cache usage="read-only"/>
<id name="ID" column="ID" >
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
</hibernate-mapping>
编辑:
<class name="Ttable1" table="Ttable1" lazy="false" mutable="true">
<cache usage="read-only"/>
<id name="ID" column="ID" >
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
</hibernate-mapping>
如果表中有一些列在访问它们之前不想加载,则可以使用lazy=true设置它们的属性映射,也可以使用组件映射这些列,并将这些组件设置为lazy=true。这样,当您第一次访问这些列时,将执行其他查询 从你给我们的东西中分辨出什么是错的是不可能的。我们不知道您的映射,表有多少列,什么都不知道
<class name="Ttable1" table="Ttable1" lazy="false" mutable="true">
<cache usage="read-only"/>
<id name="ID" column="ID" >
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
</hibernate-mapping>
问题可能由以下原因引起:
<class name="Ttable1" table="Ttable1" lazy="false" mutable="true">
<cache usage="read-only"/>
<id name="ID" column="ID" >
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
</hibernate-mapping>
- N+1选择,因为您的所有关联都是渴望的
- 数据库中有一些列包含大量数据(可能是一些附件或其他内容)
<class name="Ttable1" table="Ttable1" lazy="false" mutable="true">
<cache usage="read-only"/>
<id name="ID" column="ID" >
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
</hibernate-mapping>
您必须调试NHibernate查询并查看发生了什么。您可以通过使用show_sql、使用一些日志记录器记录日志、或使用一些探查器(如NHProf)甚至sql探查器来实现这一点
<class name="Ttable1" table="Ttable1" lazy="false" mutable="true">
<cache usage="read-only"/>
<id name="ID" column="ID" >
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
</hibernate-mapping>
您可能会看到执行了许多查询,因为没有启用延迟加载
<class name="Ttable1" table="Ttable1" lazy="false" mutable="true">
<cache usage="read-only"/>
<id name="ID" column="ID" >
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
</hibernate-mapping>
编辑:
<class name="Ttable1" table="Ttable1" lazy="false" mutable="true">
<cache usage="read-only"/>
<id name="ID" column="ID" >
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
</hibernate-mapping>
如果表中有一些列在访问它们之前不想加载,则可以使用lazy=true设置它们的属性映射,也可以使用组件映射这些列,并将这些组件设置为lazy=true。这样,当您第一次访问这些列时,将执行其他查询 如果需要获取用于显示的数据,则应根据表数据创建灯光对象。
<class name="Ttable1" table="Ttable1" lazy="false" mutable="true">
<cache usage="read-only"/>
<id name="ID" column="ID" >
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
</hibernate-mapping>
在任何情况下,如果获取速度是您唯一关心的问题,您可以将对象设置为mutable=false
,并设置缓存
<class name="Ttable1" table="Ttable1" lazy="false" mutable="true">
<cache usage="read-only"/>
<id name="ID" column="ID" >
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
</hibernate-mapping>
您也可以在代码中执行此操作:
<class name="Ttable1" table="Ttable1" lazy="false" mutable="true">
<cache usage="read-only"/>
<id name="ID" column="ID" >
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
</hibernate-mapping>
ICriteria crit = session.CreateCriteria(typeof(Ttable1));
crit.SetCacheable(true);
crit.SetCacheMode(CacheMode.Get);
crit.SetMaxResults(200);
IList result = crit.List();
映射-
<class name="Ttable1" table="Ttable1" lazy="false" mutable="true">
<cache usage="read-only"/>
<id name="ID" column="ID" >
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
</hibernate-mapping>
<class name="Ttable1" table="Ttable1" lazy="false" mutable="false">
<cache usage="read-only"/>
<id name="ID">
<column name="ID"/>
<generator class="identity"/>
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
如果需要获取数据以进行显示,则应根据表格数据创建灯光对象。 在任何情况下,如果获取速度是您唯一关心的问题,您可以将对象设置为
mutable=false
,并设置缓存
<class name="Ttable1" table="Ttable1" lazy="false" mutable="true">
<cache usage="read-only"/>
<id name="ID" column="ID" >
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
</hibernate-mapping>
您也可以在代码中执行此操作:
<class name="Ttable1" table="Ttable1" lazy="false" mutable="true">
<cache usage="read-only"/>
<id name="ID" column="ID" >
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
</hibernate-mapping>
ICriteria crit = session.CreateCriteria(typeof(Ttable1));
crit.SetCacheable(true);
crit.SetCacheMode(CacheMode.Get);
crit.SetMaxResults(200);
IList result = crit.List();
映射-
<class name="Ttable1" table="Ttable1" lazy="false" mutable="true">
<cache usage="read-only"/>
<id name="ID" column="ID" >
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
</hibernate-mapping>
<class name="Ttable1" table="Ttable1" lazy="false" mutable="false">
<cache usage="read-only"/>
<id name="ID">
<column name="ID"/>
<generator class="identity"/>
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
是否通过分页显示网格中的所有数据?如果是,您可以通过为输入的每个页面加载10行来为网格创建自定义分页,您可以首先使用
query.SetFirstResult(firstrowinpage)检索分页数据
和query.SetMaxResults(页面大小)代码>(HQL)
,并设置Radgrid属性grid.AllowCustomPaging=true代码>以允许自定义分页,并设置VirtualItemCount以了解允许分页的行数
<class name="Ttable1" table="Ttable1" lazy="false" mutable="true">
<cache usage="read-only"/>
<id name="ID" column="ID" >
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
</hibernate-mapping>
grdItems.VirtualItemCount =numberofrows();
您是否使用分页显示网格中的所有数据?如果是,您可以通过为输入的每个页面加载10行来为网格创建自定义分页,您可以首先使用query.SetFirstResult(firstrowinpage)检索分页数据
和query.SetMaxResults(页面大小)代码>(HQL)
,并设置Radgrid属性grid.AllowCustomPaging=true代码>以允许自定义分页,并设置VirtualItemCount以了解允许分页的行数
<class name="Ttable1" table="Ttable1" lazy="false" mutable="true">
<cache usage="read-only"/>
<id name="ID" column="ID" >
</id>
<property name="CustNumber" column="CustNumber" type="String" />
<property name="CustName" column="CustName" type="String"/>
<property name="PNo" column="PNor" type="String"/>
<property name="ONo" column="ONo" type="String"/>
<property name="Ln" column="Lns" type="String"/>
<property name="Comments" column="Comments" type="String"/>
<property name="size" column="size" type="String"/>
<property name="Qty" column="Qty" type="String"/>
</class>
</hibernate-mapping>
grdItems.VirtualItemCount =numberofrows();
我的表中没有任何映射,只有一个表,大约有20列,包含大量数据。请您建议我使用任何编码来缩短加载时间编辑内容:请帮助我,因为我必须获取大约100000行数据,即使使用lazy=“true”我的表中没有任何映射,问题也会产生,这是一个只有大约20列的表,其中包含大量数据。请您建议我使用任何编码来缩短加载时间编辑内容:请帮助我解决以下问题:我必须获取大约100000行数据,即使使用lazy=“true”我也无法访问crit.SetCacheMode(CacheMode.ReadOnly)如果Readonly属性不可用,我无法获取我按照您的指示所做的批量数据,请更正meMr Mush我在帖子中给出了映射请检查是否没有映射仅从单个表获取什么类型的失败、异常、,超时?用户未处理的常规ADO异常此异常被抛出,另外还有另一个异常System.OutOfMemory ExceptionI无法访问crit.SetCacheMode(CacheMode.ReadOnly),其中ReadOnly属性不存在。我无法获取我按照您的指令完成的批量数据,请更正meMr Mush我在帖子中给出了映射请检查它没有映射只是从单个表获取什么样的失败、异常、,超时?用户未处理的常规ADO异常此异常被抛出,另外还有另一个异常系统。OutOfMemory ExceptionTanks(用于回答)将尝试此异常tooThanks(用于回答)也将尝试此异常