Hello everyone, I have a list that has a portal id and color, and another lists with the records I need, in this list of records I need to get the color of the portal, I'm trying to get this data in the result with a subquery, but a mistake.
var pts = await _portaisRepositorio.ListarTudo();
var regs = await _contexto.licitacoes.Where(l => l.datapublicacao >= System.DateTime.Now.Date.AddDays(-2))
.GroupBy(l => new { l.nomeportal, l.idportal })
.Select(l => new LicsTotalModel
{
idportal = l.Key.idportal,
nomeportal = l.Key.nomeportal,
total = l.Count(),
cor = pts.Where(g => g.id == l.Key.idportal).Select(p => p.cor).FirstOrDefault(), // <= ERROR HERE
}).ToListAsync();
return regs;
I also tried:
cor = (from s in pts where s.id == l.Key.idportal select s.cor).FirstOrDefault(),
How can I do this? I just want to get the "color" field with the same id as the portal
Thanks!