1、去重Model定义
public delegate bool CompareDelegate<T>(T x, T y);
public class Compare<T> : IEqualityComparer<T>
{
private CompareDelegate<T> _compare;
public Compare(CompareDelegate<T> d)
{
this._compare = d;
}
public bool Equals(T x, T y)
{
if (_compare != null)
{
return this._compare(x, y);
}
else
{
return false;
}
}
public int GetHashCode(T obj)
{
return obj.ToString().GetHashCode();
}
二、控制器or DB调用
var Os = os.Distinct(new Compare<去重对象类名>((x, y) => (x != null && y != null) && (x.a== y.b))).ToList();
Os即为去重后的对象List。