问题描述
解决方案
解决方案二:
1.你应该描述问题,不要让人看图猜想2.你应该放代码,不要让人看图手打
解决方案三:
protectedvoidPage_Load(objectsender,EventArgse){DateTimedate=DateTime.Now.AddYears(-1);//所有合格人varlist=DbHelper.DbEntities.Yun_PeopleInfo.Where(p=>p.CertificateDate.Value>=date);//合格人去重复varlist2=list.OrderByDescending(p=>p.CertificateDate).GroupBy(p=>p.CardID).Select(p=>p.FirstOrDefault());//所有公司varlist3=list2.GroupBy(p=>p.Company).Select(m=>new{Company=m.Key,m.FirstOrDefault().Email,m.FirstOrDefault().Mobile,Count=m.Count()});//varlist4=list3.Where(p=>p.Count()<3);//varquery=lista.Where(p=>!listb.Any(g=>p.id==g.id&&p.no==g.no))varlist5=DbHelper.DbEntities.Yun_PeopleInfo.Where(p=>p.State>-1).GroupBy(p=>p.Company);varlist6=list5.Select(m=>new{Company=m.Key,m.FirstOrDefault().Email,m.FirstOrDefault().Mobile,Count=m.Count()});//varquery=list5.Where(p=>!list3.Any(g=>p.FirstOrDefault().Company==g.Company));//varnewQuery=list5.Concat(fromninlist3where!list5.Contains(n)selectn);//varall=list3.ToList();//varyes=list6.ToList();varresult=list6.Except(list3,newMyCompare()).ToList();}publicclassMyCompare:IEqualityComparer<Yun_PeopleInfo>{publicboolEquals(Yun_PeopleInfob1,Yun_PeopleInfob2){return(b1.Company==b2.Company&&b1.CardID==b2.CardID);}publicintGetHashCode(Yun_PeopleInfobx){returnbx.ToString().GetHashCode();}}
解决方案四:
看到的代码貌似没多大问题,你不描述问题?
解决方案五:
你的list3和list6应该是Select(r=>newYun_PeopleInfo(){..})才行,你弄了两个匿名类,没法比较
解决方案六:
另外你也不一定要用Except,你可以通过Where来过滤已经有的list6.Where(l6=>!list3.Any(l3=>l3.Company==l6.Company&&l3.CardID==l6.CardID))).ToList();
解决方案七:
如果搞这两个集合的并集怎么弄呢
解决方案八:
Union
解决方案九:
protectedvoidPage_Load(objectsender,EventArgse){#region培训日期在一年内人数不够的不合规公司DateTimedate=DateTime.Now.AddYears(-1);//所有合格人varlist=DbHelper.DbEntities.Yun_PeopleInfo.Where(p=>p.CertificateDate.Value>=date);//合格人去重复varlist2=list.OrderByDescending(p=>p.CertificateDate).GroupBy(p=>p.CardID).Select(p=>p.FirstOrDefault());//所有公司varlist3=list2.GroupBy(p=>p.Company).Select(m=>newMyObj{Company=m.Key,Email=m.FirstOrDefault().Email,Mobile=m.FirstOrDefault().Mobile,Count=m.Count()});varlist4=list3.Where(p=>p.Count<3);#endregion//总公司varlist5=DbHelper.DbEntities.Yun_PeopleInfo.Where(p=>p.State>-1).GroupBy(p=>p.Company);varlist6=list5.Select(m=>newMyObj{Company=m.Key,Email=m.FirstOrDefault().Email,Mobile=m.FirstOrDefault().Mobile,Count=m.Count()});//时间不在一年内的不合规公司varlist7=list6.Where(l6=>!list3.Any(l3=>l3.Company==l6.Company));varquery=list7.Union(list4,newMyCompare()).ToList();GridView1.DataSource=query;GridView1.DataBind();Response.Write(list7.Count()+"@"+list4.Count()+"$"+query.Count);}publicclassMyObj{publicstringCompany;publicstringEmail;publicstringMobile;publicintCount;publicstringCardID;}publicclassMyCompare:IEqualityComparer<MyObj>{publicboolEquals(MyObjb1,MyObjb2){return(b1.Company!=b2.Company);}publicintGetHashCode(MyObjbx){returnbx.ToString().GetHashCode();}}错的好辛苦