我正在尝试将这个 SQL 语句翻译成 LINQ,但我对 LINQ 很陌生
select professor.nom, professor.llinatge,
SUM(case when falta.aprovada = 1 then 1 else 0 end) as FJ,
SUM(case when falta.aprovada = 0 then 1 else 0 end) as FNJ
from falta inner join professor on falta.id_profe = professor.id_profe
group by professor.llinatge, professor.nom
我无法在 LINQ 中使用 JOIN 完成这项工作。我在 LINQ 中对此的最佳方法是:
var query = from f in db.falta
join p in db.professor
on f.id_profe equals p.id_profe
group f by new {p.nom, p.llinatge, f.aprovada} into g
select new
{
nombre = g.Key.nom + " "+ g.Key.llinatge,
fj = g.Select(s=> s.aprovada == true).Count(),
fnj = g.Select(s=> s.aprovada == false).Count()
};
谢谢!