i am trying to join 4 tables and group them accordingly and calculate a value.
var query = from sd in sdddd
join ei in eiii.Where(ei1 => ei1.bi == 110) on sd.sdi equals ei.sdi
join pch in pchhhh.Where(bpch => bpch.bi == 110) on sd.sdi equals pch.sdi
join ass in baaaa.Where(pc => pc.bi == 110) on pch.bi equals ass.bi
where ei.bi == 110
group new { sd,ei,pch, ass} by new { sd.dis,sd.dn } into x
select new bs
{
val1 = x.key.dn,
val2 = x.key.dis,
val3 = x.key.sdi,
val4 = x.key.di,
val5 = x.Sum(a=>a.pch.ab == "A" ? (a.pch.ans * a.ass.prm) : (a.pch.sb == "B" ? (a.pch.ans * a.ass.pim) : 0))
};
The issue i found was with group by function. If i remove the groupby it return data very fast, but takes lot of time when using groupby
select sd.[sdi],sd.[dnum] as 'Dept #',sd.[desc],
format(sum(case when pch.[ab]='A' then pch.[ans]*ass.prm
else pch.[ans]*.pim end),'N2')
FROM [database].[sdddd] as sd
JOIN [database].[eiii] as ei on ei.[sdi] = sd.[sdi]
join [database].[pchhh] as pch on pch.[sdi]=sd.[sdi]
join [database].[ass] as ass on ass.bi = pch.bi
WHERE ei.bi=110
GROUP BY sd.[desc],sd.[dnum],sd.[sdi]
ORDER BY sd.[dnum]
Original sql query which works fine. I was just trying to convert this query of joining three different tables and grouping them together and converted into linq