VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > c#编程 >
  • C#教程之泛型编程去掉字段重复数据的方法

代码如下:

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



相关教程