I had an access to modified closure error in the code below
foreach (var user in Entities.User)
{
bool any = Entities.Person.Any(
p => p.Name == user.Name);
}
So I changed it to
foreach (var user in Entities.User)
{
User theUser = user;
bool any = Entities.Person.Any(
p => p.Name == theUser.Name);
}
Now, the question is that I want to be able to modify a property of the user object. Does it matter if I do either of the following. Will they both save down to the database when I call SaveChanges on the DbContext?
user.Property = 1;
or
theUser.Property = 1;
Yes.
Userin this case is most likely a referencec type and thus variables of that type are just references pointing to an instance. The assignment just changes another variable to point to the same instance.