问题描述
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???
解决方案
本帖最后由 q107770540 于 2016-07-08 03:05:39 编辑
解决方案二:
你们项目不存在数据库,只能靠linq统计?
解决方案三:
都是在用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),};
解决方案六:
引用4楼q107770540的回复:
其实没什么难度,关键是要自己能下手写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),};
会者不难,难者不会