0

How can I convert the following SQL Query to LINQ

MY SQL Query:

 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

please see Image the SQL query result for your info

enter image descriptionhere

I have tried the following LINQ Query code but it brings records repeated:

  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)
                        }; 
MJ X
  • 8,506
  • 12
  • 74
  • 99

0 Answers0