Restless, but it works:
private class StructuralTupleComparer<T>: IEqualityComparer<Tuple<T, T>>{ private IEqualityComparer<T> _cmp; public StructuralTupleComparer(IEqualityComparer<T> cmp){ this._cmp = cmp } public bool Equals(Tuple<T, T> t1, Tuple<T, T> t2) { return _cmp(t1.Item1, t2.Item1) && _cmp(t1.Item2, t2.Item2); } public int GetHashCode(Tuple<T, T> t) { return _cmp.GetHashCode(t.Item1) ^ _cmp.GetHashCode(t.Item2) } }
and then
var myList = myEF.GroupBy(e => new Tuple<String, String>(e.Code, e.Description), new StructuralTupleComparer(StringComparer.InvariantCultureIgnoreCase)) .Select(e => e.First()) .ToList();
and hope that at some point in the glorious future there will be a method for extending static IGrouping GroupBy<T, U>(this IEnumerable<T> src, Func<T, U> groupingprojection, Func<U, bool> equalitytester) (for Great justice)
source share