如下:
public List<Product> GetSavedProductsByUserId(int userId, int pageNumber, int pageSize)
{
var sql = @"
WITH tempGR AS
(
SELECT ROW_NUMBER() over( order by a.Id desc) as ReqIndex ,COUNT(a.Id) OVER() as ReqCount ,
B.*, C.*
FROM dbo.StoredProducts A
LEFT JOIN Product B ON A.ProductId=B.Id
LEFT JOIN ProductBase C ON B.BaseId=C.PBaseId
WHERE A.UserId=@userId
)
SELECT * FROM TEMPGR WHERE ReqIndex BETWEEN @StartIndex and @EndIndex
";
var pms = new SqlParameter[] {
new SqlParameter("@UserId",userId),
new SqlParameter("@StartIndex",(pageNumber - 1) * pageSize + 1),
new SqlParameter("@EndIndex", pageNumber * pageSize)
};
var x = SqlHelper.ExecuteDataset(CommandType.Text, sql, pms);
var re = DataTableHelper.ToList3<Product>(x.Tables[0]);
return re;
}