How to get distinct results in hibernate with joins and row-based limiting (paging)?

You can achieve the desired result by requesting a list of distinct ids instead of a list of distinct hydrated objects. Simply add this to your criteria: criteria.setProjection(Projections.distinct(Projections.property(“id”))); Now you’ll get the correct number of results according to your row-based limiting. The reason this works is because the projection will perform the distinctness check as … Read more

sorting and paging with gridview asp.net

Save your sorting order in a ViewState. private const string ASCENDING = ” ASC”; private const string DESCENDING = ” DESC”; public SortDirection GridViewSortDirection { get { if (ViewState[“sortDirection”] == null) ViewState[“sortDirection”] = SortDirection.Ascending; return (SortDirection) ViewState[“sortDirection”]; } set { ViewState[“sortDirection”] = value; } } protected void GridView_Sorting(object sender, GridViewSortEventArgs e) { string sortExpression = … Read more

MongoDB – paging

Using skip+limit is not a good way to do paging when performance is an issue, or with large collections; it will get slower and slower as you increase the page number. Using skip requires the server to walk though all the documents (or index values) from 0 to the offset (skip) value. It is much … Read more

Paging with LINQ for objects

You’re looking for the Skip and Take extension methods. Skip moves past the first N elements in the result, returning the remainder; Take returns the first N elements in the result, dropping any remaining elements. See MSDN for more information on how to use these methods: http://msdn.microsoft.com/en-us/library/bb386988.aspx Assuming you are already taking into account that … Read more