泛型中去掉指定字段重复的数据

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();
        }
    }

posted @ 2013-06-14 12:17  dodo-yufan  阅读(402)  评论(0编辑  收藏  举报