Doubt in consultation with EntityFramework

0

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;
    
asked by anonymous 26.01.2017 / 23:36

1 answer

2

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();
    
27.01.2017 / 09:41