Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Newbie to Linq
Message
General information
Forum:
ASP.NET
Category:
LINQ
Title:
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01605340
Message ID:
01605406
Views:
52
>I tried that Viv before posting and it didn't work as expected, it returned the largest invoice first then the rest in what appeared to be in random order.

Hmm. Should work (I'm assuming you had the OrderBy before the GroupBy). Simple test using:
public class Invoice
    {
        public double invoiceamount { get; set; }
        public int clientid { get; set; }
    }
const double invoiceFilterAmount = 100;

IEnumerable<Invoice> invoices = new List<Invoice>()
                {
                    new Invoice() {invoiceamount = 123.34, clientid=1},
                    new Invoice() {invoiceamount = 19.24,  clientid = 2},
                    new Invoice() {invoiceamount = 47.24,clientid = 2},
                    new Invoice() {invoiceamount = 1000.00, clientid = 1},
                    new Invoice() {invoiceamount = 122.56, clientid = 2},
                    new Invoice() {invoiceamount = 99.99, clientid = 1},
                    new Invoice() {invoiceamount = 100.00,clientid = 2},
                };

            var query = invoices.Where(x => x.invoiceamount <= invoiceFilterAmount)
                                 .OrderByDescending(x => x.invoiceamount)
                                 .GroupBy(x => x.clientid);
May not be super efficient since it's sorting all invoices rather than just those within each group - but I don't think you can do that without anonymous types.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform