Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Newbie to Linq
Message
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Titre:
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01605340
Message ID:
01605406
Vues:
51
>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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform