1
I have two tables:
1st Process containing Processoid and Situacaoprocessoid
2nd Situationthe process that contains Situationthe Process and Description
Models:
public class ProcessoModel
{
public int? ProcessoId { get; set; }
public int? SituacaoProcessoId { get; set; }
public virtual SituacaoProcessoModel SituacaoProcesso { get; set; }
}
public class SituacaoProcessoModel
{
public int? SituacaoProcessoId { get; set; }
public string Descricao { get; set; }
public virtual List<ProcessoModel> LstProcesso { get; set; }
}
I want to bring the total count of processes for each type of situation, my code below is already doing this, but I want the Description column to come the Description column of the Situation table?
var processo = db.TbProcesso
.GroupBy(p => p.SituacaoProcessoId)
.Select(p => new
{
Descricao = p.Key,
Total = p.Count()
});
In my Sql I can, the problem is to do with LINQ
SELECT
sp.Descricao, COUNT(p.SituacaoProcessoId) AS Total
FROM
processo p
LEFT JOIN
situacao_processo sp ON p.SituacaoProcessoId = sp.SituacaoProcessoId
GROUP BY p.SituacaoProcessoId
Upshot:
Have you tried using the
Join
ofLinq
? Something like.Join(p.TbSituacaoProcesso, processo.SituacaoProcessoId, situacaoProcesso.SituacaoProcessoId, 
(post, meta) => new { TbProcesso = post, TbSituacaoProcesso = situacaoProcesso })
– Ricardo Pontual
Maurício, you can post the models
Processo
andSituacaoProcesso
?– Jéf Bueno
@Ricardo had tried some things but nothing went right
– Mauricio Ferraz
@LINQ Ready, posted the models.
– Mauricio Ferraz