使用LINQ(在服务器端)实现分页



我正在使用此代码从db:获取记录

use db = new dbml.MobileDataContext(connectionString)
query {
   for rows in db.Item do
   where (
            (orgid1   = "0" || rows.OrgId1 = orgid1) 
         )
   select rows
} |> (fun s ->
         if Seq.isEmpty s then
             [||]
         else
              s 
              |> Seq.skip offset |> Seq.take (int chunk) 
              |>  Seq.map sql.Record2Item |> Seq.toArray)

但若我查看SQL事件探查器中的查询,我会发现LINQ将所有记录返回到客户端,并在客户端上获取记录的子集。

但我需要SQL查询看起来像:

... OFFSET " + offset + " ROW FETCH NEXT "  + chunk + " ROWS ONLY"

是否可以在服务器端使用分页

我找到了解决方案:

query {
   for rows in db.Item do
   select rows
   skip offset
   take chunk 
}

最新更新