问题描述
selectKeyDB,(selectcount(KeyDB)fromCompanyTotalwhereCompanyTotal.KeyDB=t.KeyDBandCreateTime<='2016-7-7'and(CompanyType!='CarSynthesizeMonitor'andCompanyType!='Service'))as'运输',(selectcount(KeyDB)fromCompanyTotalwhereCompanyTotal.KeyDB=t.KeyDBandCreateTime<='2016-7-7'and(CompanyType='CarSynthesizeMonitor'orCompanyType='Service'))as'维修',(selectcount(KeyDB)fromUserTotalwhereUserTotal.KeyDB=t.KeyDBandCreateTime<='2016-7-7')as'车辆',(selectcount(KeyDB)fromVehicleTotalwhereVehicleTotal.KeyDB=t.KeyDBandCreateTime<='2016-7-7')as'人员'from(selectKeyDBfromCompanyTotalgroupbyKeyDBunionselectKeyDBfromCompanyTotalgroupbyKeyDBunionselectKeyDBfromUserTotalgroupbyKeyDBunionselectKeyDBfromVehicleTotalgroupbyKeyDB)ast这种怎么改成LINQ???
解决方案
解决方案二:
同一个问题,不要重复发帖哦。。。
解决方案三:
vartime=Convert.ToDateTime("2016-7-7");varquery=fromtin(CompanyTotal.GroupBy(c=>c.KeyDB).Select(c=>c.Key).Union(CompanyTotal.GroupBy(c=>c.KeyDB).Select(c=>c.Key)).Union(UserTotal.GroupBy(c=>c.KeyDB).Select(c=>c.Key)).Union(VehicleTotal.GroupBy(c=>c.KeyDB).Select(c=>c.Key))lettmp=CompanyTotal.Where(x=>x.KeyDB==t&&x.CreateTime<=time)selectnew{KeyDB=t,运输=tmp.Where(s=>s.CompanyType!="CarSynthesizeMonitor"&&s.CompanyType!=“Service”).Count(s=>s.KeyDB),维修=tmp.Where(s=>s.CompanyType=="CarSynthesizeMonitor"||s.CompanyType==“Service”).Count(s=>s.KeyDB),车辆=UserTotal.Where(u=>u.KeyDB==t&&u.CreateTime<=time).Count(s=>s.KeyDB),人员=VehicleTotal.Where(u=>u.KeyDB==t&&u.CreateTime<=time).Count(s=>s.KeyDB),};
解决方案四:
2楼正解。格式就是那样了