我正在使用 Linq 和 MySql 数据库。我试图只从列表中获取前 10 个结果,但 Linq 的 Take 不会过滤结果,它只返回所有 59 个结果。
这是代码:
List<EComQuoteSearchModel> results = new List<EComQuoteSearchModel>();
//do not included quotes marked as deleted in the search results
// int deletedStatusId = (int)IMSourcingPortal.Services.ecomQuoteSystem.EComQuoteStatus.Deleted;
//&& qo.nquote_status.StatusId != deletedStatusId
results = (from qo in db.nquote_orderheaders
join st in db.nquote_status on qo.StatusId equals st.StatusId
where (qo.QuoteOrderNumber.Contains(term)
|| qo.nquote_status.Name.Contains(term)
|| qo.CustomerName.Contains(term)
|| qo.IMCustomerNumber.Contains(term))
select new EComQuoteSearchModel()
{
CustomerName = qo.CustomerName,
CustomerNo = qo.IMCustomerNumber,
QuoteNo = qo.QuoteOrderNumber,
Status = st.Name
}).ToList();
IEnumerable<EComQuoteSearchModel> firstTen = results.Take(10);
var toret = firstTen.ToList();
return toret;
任何想法表示赞赏。