Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems when attaching new dbcontexts while performing savechanges #63

Open
bjoka042 opened this issue Jun 27, 2018 · 0 comments
Open

Comments

@bjoka042
Copy link

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant