How do I make this query with EntityFramework
?
with lambda
or linq
SELECT t0051_id_medicamento, t0100_lote, SUM(t0100_qtde) FROM t0100_historico
GROUP BY t0051_id_medicamento, t0100_lote;
How do I make this query with EntityFramework
?
with lambda
or linq
SELECT t0051_id_medicamento, t0100_lote, SUM(t0100_qtde) FROM t0100_historico
GROUP BY t0051_id_medicamento, t0100_lote;
Assuming that your t0100_historico
table is represented by the Historico
entity, then your lambda expression will look something like this:
db.DbSet<Historico>()
.GroupBy(new { p.Id, p.Lote })
.Select(s => new { s.First().Id, Lote, Total = s.Sum(sum => sum.Quantidade)})
.ToList();