I have the following C# LINQ code :
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();
I have a kind of serious problem, The ProductList table is a very big and I don’t want to transfer all rows from my database server so I solve this problem by taking 50 rows which is my necessary but the problem is I want to order by descending first of all and then take 50 rows but this code first take 50 rows by ascending and then order by decending only those 50 rows that has already transferred and sorted. how I can fix this ?
No, the code you’ve given:
… in that order.
On the other hand, it’s a slightly odd
OrderByDescendingcall to start with. If you want a different ordering applied as well you could easily do that too – for example: