addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwchatcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscrosseditemptyheartexportfacebookfolderfullheartglobegmailgoogleimagesinstagramlinklocation-pinmagnifying-glassmailminusmoremuplabelShape 3 + Rectangle 1outlookpersonplusprice-ribbonImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruseryahoo

RE: [dotnet-120] LINQ2SQL and sorting in ListView

From: user 4.
Sent on: Monday, November 5, 2007 4:44 PM

To get Linq2SQL to make use of ROWNUMBER you use the Take() and Skip() methods of IQueryable.   For example:

 

var results = (from item in context.TableName select item).Skip(50).Take(50);

 

This will return the records between 50 and 100 of the result set and will use ROWNUMBER or TOP on the server to limit the results.  If you can take the memory hit to store the rows from the queury in memory, then you can turn the Linq2SQL query into an in memory list by using ToList() on the results.  From that you can sort it as needed without hitting the server again.  If you can’t hold the results in memory then you will need to go to the server again for sorted results.

 

From: [address removed] [mailto:[address removed]] On Behalf Of Erb Cooper
Sent: Monday, November 05,[masked]:50 PM
To: [address removed]
Subject: RE: [dotnet-120] LINQ2SQL and sorting in ListView

 

The databinding will have no influence on the LINQ query or the Db behind it, but could optimize by not requesting rows beyond its window, using virtualization.  One would hope LINQ2SQL would make use of native SQL/database optimizations in terms of sorting, but I don't see how you can do anything besides redoing the query when the sort changes.  It's a different sort, hence a different SQL query.

 

From: [address removed] [mailto:[address removed]] On Behalf Of Alec Bryte
Sent: Monday, November 05,[masked]:43 PM
To: [address removed]
Subject: RE: [dotnet-120] LINQ2SQL and sorting in ListView

 

 

SQL2005 has a ROW_NUMBER() (http://msdn2.microsoft.com/en-us/library/ms186734.aspx) feature which allows you to perform paging on the SQL server side and return just the right set of rows. ASP.NET 2.0 SqlDataSource already utilizes it for paging through data, e.g. with GridView control.

 

Not sure if LINQ2SQL and WPF databinding utilizes it though.

 

-Alec.

 

 


From: [address removed] [[address removed]] On Behalf Of Erb Cooper [[address removed]]
Sent: Monday, November 05,[masked]:22 PM
To: [address removed]
Subject: RE: [dotnet-120] LINQ2SQL and sorting in ListView

Not sure how the 2 are related.  You need to sort the entire collection before you know which the first 100 are.

 

From: [address removed] [mailto:[address removed]] On Behalf Of Alec Bryte
Sent: Monday, November 05,[masked]:37 PM
To: [address removed]
Subject: [dotnet-120] LINQ2SQL and sorting in ListView

 

Hey Guys,

 

Has anyone attempted to use sorting when binding a result set from a LINQ select query to a ListView.

I found several examples on the web but they all use an offline collection of items.

 

Right now when a user clicks a column header for sorting, I'm redoing the query with a different "orderby" clause in it and rebinding it to the ListView, but something is telling me there is an easier way to do it. I wonder if there is a built-in support for optimized SQL data retrieval and pagination/virtualization, e.g. if I have[masked] records, the ListView should retrieve only the first 100 or something, until a user scrolls down to see the next 100 batch.

 

Thanks,

-Alec.





--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Alec Bryte ([address removed]) from New York .NET Meetup Group.
To learn more about Alec Bryte, visit his/her member profile
To unsubscribe or to update your mailing list settings, click here

Meetup.com Customer Service: [address removed]
632 Broadway New York NY 10012 USA





--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Erb Cooper ([address removed]) from New York .NET Meetup Group.
To learn more about Erb Cooper, visit his/her member profile
To unsubscribe or to update your mailing list settings, click here

Meetup.com Customer Service: [address removed]
632 Broadway New York NY 10012 USA





--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Alec Bryte ([address removed]) from New York .NET Meetup Group.
To learn more about Alec Bryte, visit his/her member profile
To unsubscribe or to update your mailing list settings, click here

Meetup.com Customer Service: [address removed]
632 Broadway New York NY 10012 USA





--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Erb Cooper ([address removed]) from New York .NET Meetup Group.
To learn more about Erb Cooper, visit his/her member profile
To unsubscribe or to update your mailing list settings, click here

Meetup.com Customer Service: [address removed]
632 Broadway New York NY 10012 USA

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy