嗨,我最近学习了实体框架和 linq,我被要求转换这个存储过程:
CREATE PROCEDURE [dbo].[GetBooks]
@numberOfBooksOnPage int,
@pageNumber int
AS
BEGIN
WITH AllBooks AS
(
SELECT ROW_NUMBER() OVER(ORDER BY Id) AS RowId,
Id , Name , Author , Description , PublicationDate , CategoryId
FROM Books
)
SELECT Id , Name , Author , Description , PublicationDate , CategoryId
FROM AllBooks
WHERE RowId BETWEEN ((@pageNumber - 1) * @numberOfBooksOnPage) + 1 AND @pageNumber * @numberOfBooksOnPage
ORDER BY RowID
END
到目前为止,我只设法获得每页显示的书籍总数,但我仍然需要找到一种通过 pageNumber 获取书籍的方法。
这是我到目前为止所拥有的:
var books = bookContext.Books.Take(numberOfBooksOnPage);
那么如何在我的 linq 查询中表示存储过程中写入的内容呢?