4
How can I reproduce the query then to LINQ expression?
SELECT nome_empresa,
Count(funcionarios.id_funcionario) AS qtdfuncionario,
Count(id_colaborador) AS qtdcolaboradores
FROM empresas
JOIN funcionarios
ON funcionarios.id_empresa = empresas.id_empresa
LEFT JOIN colaborador
ON colaborador.id_funcionario = funcionarios.id_funcionario
GROUP BY nome_empresa
This is what I have done so far, but I have not yet achieved the result:
var resultado = from e in db.empresas
join f in db.funcionarios on e.id_empresa equals f.id_empresa into eGroup
from f in eGroup.DefaultIfEmpty()
join c in db.colaborador on f.id_funcionario equals c.id_funcionario into eGroup2
from c in eGroup.DefaultIfEmpty()
select new
{
NomeEmpresa = e.nome_empresa,
CountFuncionario = e.funcionarios.Count,
Colaboradores = eGroup2.Count(t => t.id_colaborador != null)
};
You are using Entity Framework?
– Leonel Sanches da Silva
Yes I am ultilizing
– Bruno Braga
It would be interesting to post the code you have already done. As it stands, you are only asking for an answer without exerting effort to reach it.
– Juliano Alves