繁体   English   中英

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

[英]How to write a linq statement to check if a record exists then make changes to it?

我想编写一个linq语句,这样如果一条记录存在,那么对一个object属性进行更改,只需将它保留在之前的状态。

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

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但未获得成功。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM