[英]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.