Im facing a very strange problem. I have a list and am trying to update one of its inner structure field from the following for loop.
foreach (var item in AppUserDetail )
{
int AppUserID = item.AppUserId;
List<int> list = templateCategory.AppUserTemplateCategorySecurityGroupXrefs.Where(a => a.AppUserId == AppUserID).Select(b => b.SecurityGroupId).ToList();
item.AppUserSecurityGroupXrefs.Where(a => list.Contains(a.SecurityGroupId)).Select(b => b.SecurityGroup).Select(c => c.Selected = true);
bool s = item.AppUserSecurityGroupXrefs.Where(a => list.Contains(a.SecurityGroupId)).Select(b => b.SecurityGroup).Select(c => c.Selected).FirstOrDefault();
}
return AppUserDetail;
On the third line in loop, as you can see Im changing a value to True using select itself. When I run the application the value looks unchanged on the returning object. But if we execute the same line in immediate window by putting a break point inside the loop, it update the Data and it reflects at the returning object AppUserDetail. Am really getting confused why its only update from Immediate window, not from direct code execution.
item.AppUserSecurityGroupXrefs.Where(a => list.Contains(a.SecurityGroupId)).Select(b => b.SecurityGroup).Select(c => c.Selected = true);