Search code examples
nhibernateradgridicriteria

How to Load the RadGrid when fetching a huge data from the Table of the database using Nhibernate


I like to reduce the loading time when running the Default.aspx in the browser because it is fetching a huge data from the Table in the database.

When I use criteria.SetMaxResults(200) the grid load only 200 datas but I should load all the data's in the RadGrid from the table in the database .When I use criteria.SetFetchSize(200) it takes also a huge time to Load can anyone help me to find a solution for this.

Here is the code

    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();
    }

Here the Mapping is

  <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>

Here is the class using System; using System.Collections.Generic; using System.Linq; using System.Text;

   namespace Business.entities
      {
   public  class Ttable1
        {
    public virtual string displayobj { get; set; }
    public virtual Ttable1 TLQDataObj { get; set; }

    public virtual int?  ID  { get; set; }
    public virtual string CustNumber { get; set; }
    public virtual string CustName  { get; set; }
    public virtual string PNo  { get; set; }
   public virtual string ONo  { get; set; }
 public virtual string Ln { get; set; }
 public virtual string Comments  { get; set; }
  public virtual string size  { get; set; }
  public virtual string Qty  { get; set; }

   }
}

Solution

  • Are you show all data in grid with paging? if yes you can create custom paging for your grid by load 10 rows for every page you entered you can first retrieve paged data by using query.SetFirstResult(firstrowinpage); and query.SetMaxResults(pageSize); (HQL) , and set Radgrid property grid.AllowCustomPaging = true; to allow custom paging and set VirtualItemCount to know grid how number of rows to allow paging.

    grdItems.VirtualItemCount =numberofrows();