var q= (Context.invoices // Start at invoices because this is the list we really care about .Include(inv => inv.client) // Eager load the client so it doesn't require additional queries .Where(inv => inv.invoiceamount >= InvoiceAmount) .OrderByDescending(x => x.invoiceamount)// Filter results); var result = q.GroupBy(inv => inv.client) // Group results by client so we can loop through the clients .ToList()); // Execute the queryBTW There's an interesting side effect of GroupBy in this situation : The clients will be listed in descending order by their largest invoice - which is probably not what you want.....
>var results = (Context.invoices // Start at invoices because this is the list we really care about > .Include(inv => inv.client) // Eager load the client so it doesn't require additional queries > .Where(inv => inv.invoiceamount >= InvoiceAmount) > .OrderByDescending(x => x.invoiceamount)// Filter results > .GroupBy(inv => inv.client) // Group results by client so we can loop through the clients > .ToList()); // Execute the query >>
>Company: Steve Hall Fire Protection (id: 8) > Invoice reference: PJK\Steve Hall Fire Prevention\30-06-2014-0007 > Invoice date: 30/06/2014 > Invoice amount: £20,000,000.00 > Charge type: Daily Rate > Invoice reference: PJK\Steve Hall Fire Prevention\30-06-2014-0008 > Invoice date: 30/06/2014 > Invoice amount: £20,000,000.00 > Charge type: Daily Rate > Invoice reference: PJK\Steve Hall Fire Prevention\27-06-2014-0003 > Invoice date: 27/06/2014 > Invoice amount: £6,000,000.00 > Charge type: Daily Rate > Invoice reference: PJK\Steve Hall Fire Prevention\30-06-2014-0005 > Invoice date: 30/06/2014 > Invoice amount: £20,000,000.00 > Charge type: Daily Rate > Invoice reference: PJK\Steve Hall Fire Prevention\30-06-2014-0006 > Invoice date: 30/06/2014 > Invoice amount: £20,000,000.00 > Charge type: Daily Rate >>