使用Linq to SQL的Next和Previous链接

时间:2008-12-19 05:39:53

标签: linq-to-sql

我需要将“Next”和“Previous”链接添加到按日期顺序显示消息的网页。 SQL表包含MessageNumber,Subject和Date。目前我正在使用一个使用ROW_NUMBER函数的存储过程:

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

使用Linq to SQL如何在给定当前消息编号的情况下生成指向“Next”和“Previous”消息编号的链接以及表在日期中排序的位置 购买?

1 个答案:

答案 0 :(得分:1)

Skip()和Take()可用于分页功能。

例如:

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