Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Newbie to Linq
Message
From
11/08/2014 14:05:59
 
 
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:
01605460
Views:
49
>>>>That did it guys ( ordered it in the invoice loop )
>>>
>>>Pity (g) - I would love to have known why the OrderBy/GroupBy option didn't work.
>>>Maybe Rob knows ?
>>>
>>> very strange though
>>
>>Not entirely sure, but if I had to guess, the grouping operation might be done in parallel, so the order may be lost when the results are recombined.
>
>I thought Linq was sequential (unless you specifically use PLinq) but I could be wrong.
>
>I came across this (which, of course, may not be correct): http://stackoverflow.com/questions/204505/preserving-order-with-linq
>
>Snip : " GroupBy - The IGrouping objects are yielded in an order based on the order of the elements in source that produced the first key of each IGrouping. Elements in a grouping are yielded in the order they appear in source."
>
>This was certainly the behaviour in my tests - i.e. invoice amounts were in the right order, clients ordered by descending largest invoice.

Your previous attempt with the two queries might have worked then if it was brought locally (AsEnumerable or ToList) before the grouping. As is, it was left as an IQueryable so the group by was probably executed on the server as a new query rather than using the previous results. The GroupBy probably also forced a new ordering.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform