当我试图设置IsDefault每个敷料项目的属性匹配条件时,它会抛出错误说:
序列包含多个匹配序列.
(this.DressingItems
.Where(xx => xx.DressingInfo.CatID == catId
&& xx.ProductID == this.ProductID)
.Single()).IsDefault = false;
Run Code Online (Sandbox Code Playgroud)
Mat*_*ten 12
好吧,这个例外表明序列DressingItems中至少有两项符合您的Where条件.对Singlethen 的调用会导致异常,因为它断言只传入一个项目.
阅读你的问题让我觉得你想对输入序列的每个项目做一些事情,所以你可能会使用foreach循环:
foreach(var item in this.DressingItems.Where(xx => xx.DressingInfo.CatID == catId && xx.ProductID == this.ProductID))
{
item.IsDefault = false;
}
Run Code Online (Sandbox Code Playgroud)
this.DressingItems.Where(x=> x.DressingInfo.CatID == catId &&
x.ProductID == this.ProductID).ToList()
.ForEach(item=>item.IsDefault = false);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
42803 次 |
| 最近记录: |