如何编写 linq 语句以检查记录是否存在,然后对其进行更改

本文关键字:然后 存在 语句 linq 何编写 检查 是否 记录 | 更新日期: 2023-09-27 18:31:39

我想写一个linq语句,以便如果记录存在,则对对象属性之一进行更改,否则只需将其保留在以前的状态即可。

请在下面纠正我,我无法形成它?

ButtonColor = (from yy in cn.OrderDressings 
               where yy.OrderID == this.OrderID && yy.OrderItemID == this.ProductID 
               select yy.IsApplied == true) ? ButtonColor.Green : ButtonColor.Red

我试图使用FirstOrDefault.Any但没有成功。

如何编写 linq 语句以检查记录是否存在,然后对其进行更改

ButtonColor = cn.OrderDressings
                .Any(x=>x.OrderID == OrderID &&
                        x.OrderItemID == ProductID) ? ButtonColor.Green : ButtonColor.Red;
相关文章: