Next and Previous Links Using Linq to SQL

I need to add "Next" and "Previous" links to a webpage that displays posts in date order. The SQL table contains the message number, subject and date. I am currently using a stored procedure that uses the ROW_NUMBER function:

with MessageList AS
(
select msg_num,
row_number () over (order by msg_date) as rownum
from tblHeaders)

SELECT

        nextrow.msg_num AS NextMsg
FROM
        MessageList currow
LEFT JOIN MessageList nextrow
        ON currow.rownum = nextrow.rownum - 1
LEFT JOIN MessageList prevrow
        ON currow.rownum = prevrow.rownum + 1
where currow.msg_num = @msgnum

Using Linq to SQL, how would I create links to the "Next" and "Previous" numbers given the current post number and where is the table sorted in order date?

0


source to share


1 answer


Skip () and Take () can be used for swap functions.

For example:



Queryable<Customer> custQuery3 =
    (from custs in db.Customers
     where custs.City == "London"
     orderby custs.CustomerID
     select custs)
    .Skip(1).Take(1);

      

http://msdn.microsoft.com/en-us/library/bb386988.aspx

+1


source







All Articles