日期:2014-05-17 浏览次数:20457 次
public class UserComparer : IEqualityComparer<User> { public bool Equals(User u1, User u2) { return u1.Name==u2.Name; } public int GetHashCode(User u) { return u.ToString().GetHashCode(); } } var query=db.Users.Disctinct(new UserComparer());
------解决方案--------------------
public class UserComparer : IEqualityComparer<User> { public bool Equals(User u1, User u2) { return u1.Name==u2.Name; } public int GetHashCode(User u) { return u.ToString().GetHashCode(); } } var query=db.Users.Where(u=>u.Name.EndWith("z")) .OrderByDescending(u=>u.userid) .Disctinct(new UserComparer());