The previous code here did not help me ..
I also had a problem with this. First, Distinct works, but only after the QueryOver.List.ToList () method has been called, so query.skip will not work properly, redrawing duplicates, creating a list, and then decreasing my calculated amount due to duplicates .
The simplest thing I found is to simply create a list of unique identifiers first, and then paginate the identifiers themselves.
Then, on your result set, you can simply execute the identifier and get the identifiers only in your new paginated result set.
//Create your query as usual.. apply criteria.. do what ever you want. //Get a unique set of ids from the result set. var idList = query. .Select(x => x.Id) .List<long>().Distinct().ToList(); //Do your pagination here over those ids List<long> pagedIds = idList.Skip(0).Take(10).ToList(); //Here what used to be non distinct resultset, now is.. List<T> resultquery.Where(() => item.Id.IsIn(pagedIds)) .List<Person>() .ToList();
Special thanks .. https://julianjelfs.wordpress.com/2009/04/03/nhibernate-removing-duplicates-combined-with-paging/
Jeffrey holmes
source share