Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi,

I would like to order my data list by date descending based on my joined table of SQL database.

I have this code;
C#
var dataTransfer2 = dataTransfer.Join(smlPortal.SML_QC_SokuteiRejectsTransaction, a => a.Id, b => b.SokuteiRejectId, (a, b) => new
           {
               a.Id,
               a.PlasticNo,
               a.LotNo,
               b.transactionBy,
               b.transactionNotes,
               b.transactionType,
               b.transactionDate,
           }).Take(5).ToList();


What I have tried:

i tried to put .OrderbyDescending after and before .Join
Posted
Updated 2-Apr-21 7:39am
v2
Comments
[no name] 1-Apr-21 23:51pm    
Do the sort on the result (dataTransfer2). Before or after you take 5.

1 solution

added OrderbyDescending(b=>b.transactionDate) before take(5)

var dataTransfer2 = dataTransfer.Join(smlPortal.SML_QC_SokuteiRejectsTransaction, a => a.Id, b => b.SokuteiRejectId, (a, b) => new
            {
                a.Id,
                a.PlasticNo,
                a.LotNo,
                b.transactionBy,
                b.transactionNotes,
                b.transactionType,
                b.transactionDate,
            }).Take(8).OrderByDescending(b => b.transactionDate).ToList();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900