Skip to content

Paging DataSets for DataTables using NHibernate

August 30, 2012

If you are paging datasets for datatables using NHibernate C#, be warned that you have to always update the range of data of starting point and end point for the DataTable.

 

Like so: –

 

public static IList<Type> GetAllRecords(int firstRecord, int max)
{
ICriteria criteria = SessionFactoryContext.GetCurrentSession().CreateCriteria(typeof(Type));
criteria.Add(NHibernate.Criterion.Expression.Eq(“Deleted”, false));
criteria.SetFirstResult(firstRecord);
criteria.SetMaxResults(max);
return (IList<Type>)criteria.List<Type>();
}

 

Before I had omitted the criteria.SetMaxResults(max) which sets the maximum records, and this affects the number of data objects being stored in the IList for your DataTable, so if you wanted to set a maximum of 100 records to be displayed, the max will be set to 100 dynamically, don’t hardcode the value which I had set it to 100. If you have a dropdown list to set to 25, to be displayed, you will still get 100. This caused little bugs on my program when displaying the page totals!! Lesson learnt!

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: