我使用linq語句來獲取我的公司評論,但它跳過了錯誤的結果。Linq跳過跳過錯誤的結果?
如果我通過它currentPage = 1它會得到正確的結果,如果我通過它currentPage 2它做錯了。每頁的評論數量爲10. GUID ID也正確傳遞。
public IList<SupplierReview> GetAmount(int pageAmount, int currentPage, Guid companyId)
{
var total = _context.SupplierReview.Count();
var skipAmount = pageAmount * (currentPage - 1);
if (skipAmount < total)
{
if (pageAmount < (total - skipAmount))
{
//return the page amount of reviews
return _context.SupplierReview
.Where(x => x.Company.Id == companyId)
.OrderBy(x => x.Id)
.OrderBy(x => x.ReviewDate)
.Skip(skipAmount)
.Take(pageAmount)
.ToList();
}
else
{
//if the left amount is less than the pageAmount,
//then only the leftovers should get taken
return _context.SupplierReview
.Where(x => x.Company.Id == companyId)
.OrderBy(x => x.Id)
.OrderBy(x => x.ReviewDate)
.Skip(skipAmount)
.Take(total - skipAmount)
.ToList();
}
}
//if nothings left, return null
return null;
}
錯誤可能是愚蠢的,但我似乎無法看到它......任何想法?
謝謝!
第二次調用'OrderBy'(在每個查詢中)應該是'ThenBy'而不是?第一個'OrderBy'被扔掉了。 – Mephy