The following calls DB every time to get the list of users by id.
foreach (User user in users)
{
db.Users.Where(w => users.Any(a => a.Id == w.Id)).ToList().
ForEach(x => {
x.name = user.name;
x.cat = user.cat;
});
}
db.SaveChanges();
Is there a way to do this with out going in the loop each time.
Get the list of users first, update them, then save changes. You would still need a foreach to update it though. This takes the List and selects only the Id, turning it into List (or whatever your ID field is), then gets all the users in that list from the database, updates them, and saves.
var dbUserList = db.Users.Where(x => users.Select(y => y.Id).Contains(x.Id));
foreach (var user in users)
{
var dbUser = dbUserList.First(x => x.Id == user.Id);
dbUser.name = user.name;
dbUser.cat = user.cat;
}
db.SaveChanges();