-
Notifications
You must be signed in to change notification settings - Fork 269
Open
Description
Backstory: I have implemented repositories that store the data. In each of the DbContext models i have attached an auditlog handler to catch changes and log them using another repository.
public override int SaveChanges(bool acceptAllChangesOnSuccess)
{
AuditLog[] logs = null;
if (_auditLogTracker != null)
logs = _auditLogTracker.TrackChanges(this);
var result = base.SaveChanges(acceptAllChangesOnSuccess);
if (_auditLogTracker != null && logs != null)
_auditLogTracker.Save(logs);
return result;
}
Error: Collection was modified; enumeration operation may not execute.
The error is due to a new context being added while looping through contexts and performing commit.
Could the DbContextCollection perform other than foreach loops to go through the list to allow for new contexts being added during savechanges?
for(var i = 0; i contexts.length; i++)
{
//would probably allow for dynamicly injected contexts
}
Metadata
Metadata
Assignees
Labels
No labels