泛型编程去掉字段重复数据的方法
public partial class v_myjoinedcloudrespository
{
public list<v_myjoinedcloud> 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<v_myjoinedcloud> list = new list<v_myjoinedcloud>();
if (lamd!=null&&lamd.count()>0)
{
list = lamd.tolist();
list = list.distinct(new companynamecomparer()).tolist();
}
return list;
}
}
public class companynamecomparer : iequalitycomparer<v_myjoinedcloud>
{
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();
}
}