序列包含一个以上的匹配元素 [英] Sequence contains more than one matching element

查看:1908
本文介绍了序列包含一个以上的匹配元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我试图设置每个敷料项目ISDEFAULT财产,其中匹配它抛出一个错误说序列包含多个匹配序列的条件。

 (this.DressingItems 
。凡(XX => xx.DressingInfo.CatID == CATID
和;&安培; xx.ProductID == this.ProductID)
。单())ISDEFAULT = FALSE。


解决方案

 这一点。 DressingItems.Where(X => x.DressingInfo.CatID == CATID和放大器;&安培; 
x.ProductID == this.ProductID).ToList()
.ForEach(项目=>的项目。 ISDEFAULT = FALSE);


when i am trying to set IsDefault property of each dressing items where match a condition it throws an error saying Sequence contains more than one matching sequence.

(this.DressingItems
     .Where(xx => xx.DressingInfo.CatID == catId 
                        && xx.ProductID == this.ProductID)
     .Single()).IsDefault = false;

解决方案

this.DressingItems.Where(x=> x.DressingInfo.CatID == catId && 
                                x.ProductID == this.ProductID).ToList()
                 .ForEach(item=>item.IsDefault = false);

这篇关于序列包含一个以上的匹配元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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