I need to add "Next" and "Previous" links to a Web page displaying messages in date order. A SQL table holds the MessageNumber, Subject and Date. Currently I am 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 generate links to the "Next" and "Previous" message numbers given the current message number and where the table is sorted in date order?