Click here to Skip to main content
15,445,242 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my project was created using c# & entity framwork 6
i have this table (entries) that have status filed
the status filed will fill with one of this values :

i want to retrieve all the record sorted with this conditions:-
Accepted rows first then Pending rows, then Delayed, and the completed and reject the last.

What I have tried:

var Query = DB1.entries.Where(u=> >= From && <= To && statusList.Contains( u.Status)).Select(s => new entires
                ID =,
                Name = s.Name,
                date =,
                Order = s.order,
                Topic = s.Topic,
                ExternalVisitor = s.ExternalVisitor == 1 ? true : false,
                Reason = s.Reason,
                waiting = s.waiting,
                Status = s.Status,
            }).OrderBy(o => o.Status == "pending").ThenByDescending(o =>;
Updated 13-Sep-20 12:39pm

1 solution

...OrderBy( o => 

switch( o.Status ) {
   case "Accepted": return 1;
   case "Pending": return 2;
   default: return 6;
} )
.ThenBy ... etc.
Share this answer
Golden Basim 14-Sep-20 1:26am     CRLF
i tried that but it seem that it don't accept to write switch inside orderby(). error line appear below the code. Error CS1026 ) expected Error CS1525 Invalid expression term 'switch' Error CS0127 Since 'Entries.fillGrid()' returns void, a return keyword must not be followed by an object expression

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