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:
01605456
Vues:
44
>Your last suggestion sent it into a hissy fit - I think I'll have to call it a day my brain hurts - when you say use an anonymous type how could that help ?

You could do something like this (based on the simple invoices example I posted earlier):
            var query2 = invoices.GroupBy(x => x.clientid)
           .Select(group => new { Id = group.Key, invs = group.OrderByDescending(x => x.invoiceamount) })
           .OrderByDescending(group => group.invs.Sum(x => x.invoiceamount));

            foreach (var q in query2.ToList())
            {
                Console.WriteLine("\nClient Id: {0}.", q.Id);
                foreach (var x in q.invs)
                {
                    Console.WriteLine("\t{0:C}", x.invoiceamount);
                }
                Console.WriteLine("\n\tTotal: {0:c}\n", q.invs.Sum(x => x.invoiceamount));
}
The last .OrderByDescending is just a frill so that the clients are listed in order of total invoices value.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform