Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将Sql查询转换为linq_C#_Sql Server_Linq - Fatal编程技术网

C# 将Sql查询转换为linq

C# 将Sql查询转换为linq,c#,sql-server,linq,C#,Sql Server,Linq,大家好,我想把这个sql查询转换成linq查询。但是我有一些问题我不知道怎么解决请帮助我 我的sql查询 select SERVICESLASBYCOUNTRY.id,site.Name, SERVICESLASBYCOUNTRY.countrycode, sum(SERVICESLASBYCOUNTRYDETAILS.estddays) as estddays from SERVICESLASBYCOUNTRY inner join site on SERVICESLASBYCOUNTRY.S

大家好,我想把这个sql查询转换成linq查询。但是我有一些问题我不知道怎么解决请帮助我

我的sql查询

select SERVICESLASBYCOUNTRY.id,site.Name, SERVICESLASBYCOUNTRY.countrycode, sum(SERVICESLASBYCOUNTRYDETAILS.estddays) as estddays
from SERVICESLASBYCOUNTRY
inner join site on SERVICESLASBYCOUNTRY.SiteId = site.id
inner join SERVICESLASBYCOUNTRYDETAILS on SERVICESLASBYCOUNTRY.id = SERVICESLASBYCOUNTRYDETAILS.servicelasbycountrykey
where SERVICESLASBYCOUNTRY.servicecode = 234
group by SERVICESLASBYCOUNTRYDETAILS.servicelasbycountrykey,site.Name, SERVICESLASBYCOUNTRY.countrycode,SERVICESLASBYCOUNTRY.id
这是我尝试,但它有一些错误,请帮助我删除此

from s in db.SERVICESLASBYCOUNTRies
                               join si in db.sites on s.SiteId equals si.id
                               join sd in db.SERVICESLASBYCOUNTRYDETAILs on s.id equals sd.servicelasbycountrykey 
                               where s.servicecode == servicecode
                               group sd by sd.estddays into bhh 
                               select new SLACountryDTO                        
                               {
                                   ID = s.id,
                                   ServiceCode = s.servicecode,
                                   CountryCode = s.countrycode,
                                   SiteId = s.SiteId,
                                   SiteName = si.Name,
                                   Sum = bhh.Sum(sd => sd.estddays)
                               });
错误是

"s" does not exist current context 
"si" does not exist current context

就像您在SQL查询中执行的
分组一样,您需要在LINQ查询中执行以下操作:-

from s in db.SERVICESLASBYCOUNTRies
      join si in db.sites on s.SiteId equals si.id
      join sd in db.SERVICESLASBYCOUNTRYDETAILs on s.id equals sd.servicelasbycountrykey 
      where s.servicecode == servicecode
      group sd by new { sd.estddays, s.countrycode,s.servicecode,s.id,s.SiteId,si.Name } 
                  into bhh 
      select new SLACountryDTO                        
      {
           ID = bhh.Key.id,
           ServiceCode = bhh.Key.servicecode,
           CountryCode = bhh.Key.countrycode,
           SiteId = bhh.Key.SiteId,
           SiteName = bhh.Key.Name,
           Sum = bhh.Sum(sd => sd.estddays)
       });

您的bhh组有一个键和一组项,您应该通过此对象获取数据。s&si在您的团队中无效

它有什么错误?