I have this SQL Query :
DECLARE @pageNo int=1
DECLARE @pageSize int=2
SELECT top 2 id,
Title,
Author,
NumberOfPages,
PublishedAt,
RowNumber
FROM
(
SELECT top 2 id, Title, Author,
NumberOfPages,PublishedAt,
Row_Number() over (order by id desc) as RowNumber
FROM Books
)T
WHERE
T.RowNumber BETWEEN ((@pageNo-1)*@pageSize)+1 AND (@pageNo*@pageSize)
I want Execute this SQL Query with C# in ASP.NET core
I tried this Code :
[HttpGet]
public async Task<ActionResult<IEnumerable<Books>>> GetBooks()
{
return await _context.Books.FromSqlRaw("Select * from Books where id = 2").ToListAsync();
}
But this Code work only with Single Sql Query Line like last example
Select * from Books where id = 2
but when I try with Complex SQL Query with Multi lines is not Working
I hope your help
thank so much