Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have below query. need to change lamda expression.

(from item in list.OrderByDescending(x => x.id).ThenByDescending(x => x.amount) where item.active== false select item).FirstOrDefault();


can you help me?

What I have tried:

tried to convert linq to lamda expression. not working
Posted

1 solution

You need to use the Linq expression format, rather than the statement format.

C#
var result = list.OrderByDescending(x => x.id).ThenByDescending(x => x.amount).Where(item=>item.active==false).FirstOrDefault();


Notice:

  • removal of the "from item in"
  • The concatenation the the Where clause
  • The introduction of the item parameter in the Where method
  • The remove of the select item
 
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