如何将以下SQL查询转换为LINQ
我的SQL查询:
SELECT id, FullName, sum(mins) as Mins
FROM (Select t.id, FullName, NumberOfSupports* st.Minutes as mins
FROM(Select st.Id, st.FullName, count(s.Id) as NumberOfSupports, s.SupportTypeId
FROM SupportTeams st
INNER JOIN Supports s on s.ResponsibleId = st.Id
GROUP BY st.id, st.FullName, s.SupportTypeId) t
INNER JOIN SupportTypes st on st.id = t.SupportTypeId) t
GROUP BY id, FullName
请参阅图片查询您的信息的SQL查询结果
我尝试过以下LINQ查询代码,但它会重复记录:
var minutesworked = from s in db.MySupportContext
.Where(y => y.CreatedDate.Year == currentYear)
join t in db.MySupportTeam on s.ResponsibleId equals t.Id
join st in db.MySupportTypeContext on s.SupportTypeId equals st.Id
group st by new { s.ResponsibleId, s.SupportTypeId, st.Minutes, t.FullName } into g
select new SupportChartVM
{
Responsible = g.Key.FullName,
TotalSupport = g.Sum(m => m.Minutes)
};