Linq到lamda表达式转换 [英] Linq to lamda expression conversion

查看:73
本文介绍了Linq到lamda表达式转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下查询。需要更改lamda表达式。



(来自list.OrderByDescending(x => x.id)中的项目.ThenByDescending(x => x.amount)其中item.active == false选择项目。)。firstOrDefault();





你可以帮帮我吗?



我尝试过:



试图将linq转换为lamda表达式。不工作

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

推荐答案

您需要使用Linq表达式格式,而不是语句格式。



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

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





注意:



  • 删除from item in
  • 串联 Where 子句

  • 其中方法中引入 item 参数
  • 删除选择项目


  • 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

    • 这篇关于Linq到lamda表达式转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆