0

as am a beginner,i want to get the following set of query as linq with a detailed explanation

//my sql

select COL.title as organizationtitle,CL.[title] as 
cousestitle,sum(FD.feathers) as totalfeathers,sum(FD.amount) as 
totalamount
from  [dbo].[FeathersDonated]  FD 
join [dbo].[Couses] C  on FD.corpid=3 and FD.[cousesid]=C.id 
join [dbo].[Couses_lang] CL on FD.[cousesid]=CL.cousesid and 
CL.language='en-US'
JOIN [dbo].[Organization_lang] COL on COL.orgid=2 and COL.language='en 
US' 
group by FD.cousesid,CL.[title],CL.[description],COL.title

i have tried the following set of code. please do help

var featherDonated = _GoUoW.FeathersDonated.FindBy(x => x.corpid == 
param.corpid)
.GroupBy(x => x.cousesid).Select(x => new { cousesid = x.Key, amount = 
x.Select(a => a.amount).DefaultIfEmpty(0).Sum(), feathers = x.Select(a => 
a.feathers).DefaultIfEmpty(0).Sum() })
.Join(_GoUoW.Couses.GetAll(), feather => feather.cousesid, couse => 
couse.id, (feather, couse) => new { feather, couse })
.Join(_GoUoW.Organization_lang.FindBy(orglang => orglang.language == "en- 
US"), couses => couses.couse.orgid, orgid => (param.organizationid > 0 ? 
param.organizationid : orgid.orgid), (couses, orgid) => new { couses, 
orgid 
})
.Join(_GoUoW.Couses_lang.FindBy(couselang => couselang.language == "en- 
US"), 
organization => organization.orgid.orgid, couselang => couselang.cousesid, 
(organization, couselang) => new { organization, couselang })
.Select(x => new
        {
            x.organization.couses.feather.amount,
            x.organization.couses.feather.feathers,
            x.couselang.title
            //x.organization.orgid.title,


        }).ToList();
Aravind
  • 27
  • 2
  • Take a look at [this](https://stackoverflow.com/questions/17730716/linq-to-sql-join-group-and-sum) and try to write your query which will help you understand and learn and if any issues come back here. – Mahesh Jun 21 '19 at 05:33
  • Possible duplicate of [Multiple joins in linq](https://stackoverflow.com/questions/13426196/multiple-joins-in-linq) – habib Jun 21 '19 at 05:33
  • Perhaps my [SQL to LINQ Recipe](https://stackoverflow.com/questions/49245160/sql-to-linq-with-multiple-join-count-and-left-join/49245786#49245786) might help you. – NetMage Jun 21 '19 at 17:32

0 Answers0