0
how do I consult 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;
0
how do I consult 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;
2
Assuming that your table t0100_historico
is represented by the entity Historico
, 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();
Browser other questions tagged mysql sql entity-framework
You are not signed in. Login or sign up in order to post.
Speak the class name of your t0100_historic table if you can help.
– Wilson Santos
the class name is Historico
– alessandre martins
Ok, try this: var db = new Dbcontext(); var result = db.Dbset<Historico>(). Tolist(). Groupby( new { p.Id, p.Lot }). Select(s => new Historico { Id = s.First().Id, Lot = s.First().Lot, Quantity = s.Sum(sum => sum.Quantity) }). Tolist();
– Wilson Santos
@Wilsonsantos If there are many records, its expression will not be legal, because it first brings all the records of history - which will probably be MANY - to then make the groupings and summaries.
– Thiago Lunardi