Im working on my school project and im new in writing LINQ query's so its hard for me to convert this SQL query to LINQ. I have problem with writing linq query for top 10 best selling products. I have table for Products and table for Selling item.
I tried with this:
List<Proizvodi> proizvodi = db.Proizvodi.
OrderByDescending(x => db.IzlazStavke.Where(y => y.ProizvodID == x.ProizvodID).
Sum(t => t.Cijena)).Take(10).ToList();
But result is not good, any help please.
I'll try something like this:
List<Proizvodi> proizvodi = db.Proizvodi
.OrderByDescending(x => db.IzlazStavke
.Where(y => y.ProizvodID == x.ProizvodID)
.GroupBy(a=>a.ProizvodID)
.Select(grp=>grp.Sum(z=>z.Kolicina))
.Take(10)
.ToList();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.