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

From: user 4.
Sent on: Tuesday, November 6, 2007 10:13 AM
I agree with you about sorting dynamically changing data.  I was thinking of cases where the list was less dynamic.  Data can be stale as soon as you read it from the database so the application needs to deal with that even without sorting.  For example paging through a list that has a changing number of records is particularly tricky to get right.   What 'right' means changes depending on users expectations of application behavior.  Search engines like google punt on this issue most of the time.  Google just does estimates on the number of search results found.  The actual number found is normally much less than the estimate.  That why I find it funny when news organizations quote Google search hit numbers since they are very inaccurate. 

-----Original Message-----
From: Kevin Hoffman <[address removed]>
Sent: Tuesday, November 06,[masked]:58 AM
To: [address removed] <[address removed]>
Subject: RE: [dotnet-120] LINQ2SQL and sorting in ListView

The problem with holding stuff in memory to make the sort penalty
smaller is you have to worry about maintaining Consistency with the
database. How do you deal with the action of people adding rows to the
database after your cache has been created? how often do you poll for
new changes? Is the performance impact of continuous polling to make the
offline cache going to offset the cost of simply having done the query
to begin with.

 

Having been down this road before, I can honestly say that I haven't yet
met an offline sort cache that works unless the app is actually designed
to work in a semi-offline fashion, in which case that pattern is ideal.

 

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

 

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.micr...­) 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/virtualiz­ation, 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
<http://dotnet.mee...;­ 
To unsubscribe or to update your mailing list settings, click here
<http://www.meetup...;­ 

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
<http://dotnet.mee...;­ 
To unsubscribe or to update your mailing list settings, click here
<http://www.meetup...;­ 

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
<http://dotnet.mee...;­ 
To unsubscribe or to update your mailing list settings, click here
<http://www.meetup...;­ 

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
<http://dotnet.mee...;­ 
To unsubscribe or to update your mailing list settings, click here
<http://www.meetup...;­ 

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 David Barnhill ([address removed]) from New
York .NET Meetup Group.
To learn more about David Barnhill, visit his/her member profile
<http://dotnet.mee...;­ 
To unsubscribe or to update your mailing list settings, click here
<http://www.meetup...;­ 

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