我有下面的C#LINQ代碼:如何通過降序來訂購,然後使用linq購買一些物品?
List<myProductList> qMain = (
from m in db.ProductsList.OrderByDescending
(it => it.GroupCode == 1 || it.L1 == 1)
where m.GoodCode == 1 || m.L1 == 1
select new myProductList
{
StackAmount = m.StackAmount,
GoodCode = m.GoodCode,
PrivateCodeForSort = m.PrivateCodeForSort,
GoodMainCode = m.GoodMainCode,
MaxSellPrice = m.MaxSellPrice,
SellPrice5 = m.SellPrice5,
SellPriceType = m.SellPriceType,
GoodExplain1 = m.GoodExplain1,
Writer = m.Writer,
DragoMan = m.DragoMan,
GoodName = m.GoodName,
Printing = m.Printing,
CoverType = m.CoverType,
PrintYear = m.PrintYear,
PrintPeriod = m.PrintPeriod,
Creation = m.CreationDate
}).Take(50).ToList();
我有一種嚴重的問題,在產品列表表是非常大的,我不想讓我解決這所有的行從我的數據庫服務器傳輸問題是需要50行,這是我的必要條件,但問題是我想先下降然後取50行,但是這個代碼首先按升序取50行,然後通過僅降低那些已經傳輸的50行來排序,排序。我如何解決這個問題?
'OrderByDescending'不喜歡的工作 - 你必須指定*如何*你想讓它訂購。 –
@JonSkeet會按照我更新答案的方式工作嗎? – Icarus
是的,雖然在查詢表達式中執行排序會更簡單。 –