How to implement IEqualityComparer to return distinct values?

An EqualityComparer is not the way to go – it can only filter your result set in memory eg: var objects = yourResults.ToEnumerable().Distinct(yourEqualityComparer); You can use the GroupBy method to group by IDs and the First method to let your database only retrieve a unique entry per ID eg: var objects = yourResults.GroupBy(o => o.Id).Select(g … Read more

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