Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Newbie to Linq
Message
De
11/08/2014 11:45:48
 
 
À
11/08/2014 09:05:36
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:
01605447
Vues:
43
>Hmm. Out of curiosity do you get the correct order after the OrderByDescending. i.e is the result of q OK using the below?:
>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 query
>
BTW 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.....
>
>
>>Hi Viv, here's some sample output from my query
>>
>>Query
>>
>>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
>>
>>
>>Sample output
>>
>>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
>>
>>
>>as you can see there's a 6,000,000.00 snuck in the middle - the same thing happens on all my test data.

You could try ordering by the client or client id, then by the invoice amount. Or if nothing else, order it when you do your loop.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform