linq - How to get top 10 customers based on values of orders -
i have list of customers
each have list of orders
. each order
has list of lineitems
.
i write linq query me top 10 customers based on order value (i.e. money spent) , not total number of orders.
one customer have 2 orders have spent £10,000, customer have 100 orders, , spent £500.
right now, have gets me top 10 customers number of orders.
var customers = (from c in _context.customers c.saleorders.count > 0 let activecount = c.saleorders.count(so => so.status != saleorderstatus.cancelled) orderby activecount descending select c).take(10);
update
thanks jon skeet's comment doing double sum
, wrote following query compiles.
var customers = (from c in _context.customers c.saleorders.count > 0 let ordersum = c.saleorders.where(so => so.status != saleorderstatus.cancelled).sum(so => so.lineitems.sum(li => li.calculatetotal())) orderby ordersum descending select c).take(10);
but when run this, following error:
it seems linq doesn't recognise .calculatetotal()
method sit on lineitem.cs
entity.
Comments
Post a Comment