大家好,提前感谢大家的解决方案
有这些对象
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; }
}
我收到listfaccessmoduleinfo已经填满,当我尝试更新特定AccessModuleInfo中的AccessRoleValue时,所有具有相同AccessRoleId的AccessRoleValue都被更新。
我只想更新特定AccessModuleInfo的AccessRoleValue(例如,AccessModuleId = 4)
谢谢
正常情况下,这样的操作应该可以正常工作:
// 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);