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:
01605476
Views:
47
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.

Good call Rob I tried Vivs code ( only slightly modified by adding ToList()) and it worked as expected - I think we've all learnt something here - thank you all for your help. Here are the two queries that work.
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).ToList();

                var results =    q.GroupBy(inv => inv.client); // Group results by client so we can loop through the clients
                     // Execute the query
Regards,
Peter J. Kane



Pete
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform