Pour une personne DB, LINQ peut être frustrant. J'ai besoin de convertir le SQL suivant en Linq.Comment puis-je obtenir ce sql à linq? Plusieurs groupes
SELECT COUNT(o.objectiveid), COUNT(distinct r.ReviewId), l.Abbreviation
FROM Objective o
JOIN Review r
on r.ReviewId = o.ReviewId
and r.ReviewPeriodId = 3
and r.IsDeleted = 0
JOIN Position p
on p.PositionId = r.EmployeePositionId
and p.DivisionId = 2
JOIN Location l
on l.LocationId = p.LocationId
GROUP BY l.Abbreviation
Le group by nested example est peut-être la façon dont je dois y aller, mais pas sûr. Faire un groupe par je l'ai utilisé le code suivant:
var query = from rev in db.Reviews
.Where(r => r.IsDeleted == false && r.ReviewPeriodId == reviewPeriodId)
from obj in db.Objectives
.Where(o => o.ReviewId == rev.ReviewId && o.IsDeleted == false)
from pos in db.Positions
.Where(p => rev.EmployeePositionId == p.PositionId && p.IsDeleted == false && p.DivisionId == divisionId)
from loc in db.Locations
.Where(l => pos.LocationId == l.LocationId)
group loc by loc.Abbreviation into locgroup
select new ReportResults
{
KeyId = 0,
Description = locgroup.Key,
Count = locgroup.Count()
};
return query.ToList();
Quelle est la bonne façon?
Merci
Il vient avec une erreur. Le premier outil ne peut pas gérer le Count(). –