0

大家好,提前感谢您的解决方案

我有这些物品

    List<AccessModuleInfo> listOfAccessModuleInfo = new List<AccessModuleInfo>();

    public class AccessModuleInfo
    {
       public int AccessModuleId { get; set; }
       public string AccessModuleName { get; set; }
       public List<AccessRoleInfo> ListOfAccessRole { get; set; }

     }

    public class AccessRoleInfo
    {
      public int AccessRoleId { get; set; }
      public string AccessRoleName { get; set; }
      public bool AccessRoleValue { get; set; }
    }

我收到已经填充的 listOfAccessModuleInfo,当我尝试更新特定 AccessModuleInfo 中的 AccessRoleValue 时,所有具有相同 AccessRoleId 的 AccessRoleValue 都会更新。

我只想更新特定 AccessModuleInfo 的 AccessRoleValue(例如 AccessModuleId = 4)

谢谢

4

1 回答 1

0

通常这样的事情应该可以正常工作:

// You didn't confuse == vs = did you?
// Single also helps us debug and ensure we're only getting one result
var itemToUpdate = listOfAccessModuleInfo.Where(x => x.AccessModuleId == 4).Single();
itemToUpdate.ListOfAccessRole.ForEach(x => x.AccessRoleValue = newValue);
于 2013-10-14T13:29:38.677 回答