泛型编程去掉字段重复数据的方法
本文导语: 代码如下:public partial class V_MyJoinedCloudRespository { public List GetDistinctJoinedCloud(string cloudName,long ExpertId) { var lamd = from p in db.V_MyJoinedCloud where p.Status == 1 && p.Comp...
public partial class V_MyJoinedCloudRespository
{
public List GetDistinctJoinedCloud(string cloudName,long ExpertId)
{
var lamd = from p in db.V_MyJoinedCloud
where p.Status == 1 && p.CompanyName.Contains(cloudName) && p.ExpertID==ExpertId
select p;
List list = new List();
if (lamd!=null&&lamd.Count()>0)
{
list = lamd.ToList();
list = list.Distinct(new CompanyNameComparer()).ToList();
}
return list;
}
}
public class CompanyNameComparer : IEqualityComparer
{
public bool Equals(V_MyJoinedCloud x, V_MyJoinedCloud y)
{
if (x == null)
return y == null;
return x.CompanyID == y.CompanyID;
}
public int GetHashCode(V_MyJoinedCloud obj)
{
if (obj == null)
return 0;
return obj.CompanyID.GetHashCode();
}
}