I'm trying to retrieve a collection of distinct users from my database.
var DistinctUsers = AllUsers.Distinct(new UserComparer());
AllUsers is an IQueryable<UserEntity> and has multiple entries for the same user. Every user has a unique ID, but there are other fields which are not identical in AllUsers. So, I came up with this simple IEqualityComparer object, which relies on the comparision of user IDs.
public class UserComparer : IEqualityComparer<UserEntity>
public bool Equals(UserEntity x, UserEntity y)
return (x.Id == y.Id);
public int GetHashCode(UserEntity x)
However, this still does not work. I'm still getting redundant users in my DistinctUsers collection.
Any ideas? Am I missing something?