I have a button with a list of users in the table ButtonUsers
. A parent Button
is updated with the list of users, and all other Buttons' UserList
should be updated. This isn't the case every time, therefore each button has it's own list.
The problem is that I have maybe 5000 buttons, that should each be updated.
I tried pulling all buttons at once, then pull the users necessary, and set each buttons state as modified. When I've iterated through all the buttons, call SaveChanges()
.
public bool UpdatePreviousButtons(Button button, List<string> userList)
{
var buttons = fieldRepo.GetFieldsCreatedFrom<Button>(button.ID);
var users = fieldRepo.GetUsersFromIDs(userList);
foreach(var btn in buttons)
{
btn.UserList = users;
fieldRepo.UpdateFieldGeneric<Button>(btn);
}
return fieldRepo.Commit();
}
The problem seems to be that it doesn't bulk insert the records, instead it inserts one record per call. This inevitably leads to a time out, and takes far to long.
I have been thinking about doing it manually with Context.Database.ExecuteSqlCommand()
. Is there a better way, using Entity Framework?