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

Optimistic ConcurrencyException thrown if doc is stored and then updated in dirty tracked session #669

Closed
barryhagan opened this issue Feb 6, 2017 · 2 comments
Labels
Milestone

Comments

@barryhagan
Copy link
Contributor

When using optimistic concurrency combined with dirty tracked sessions, you cannot make any changes to document after it is initially stored, but before .SaveChanges() is called.

Sometimes it would be nice to be able to get the auto generated Id of the object which is set on Store, and then make subsequent changes to the doc prior to saving changes.

Failing test (using code in optimistic_concurrency.cs):

        [Fact]
        public void can_store_and_update_same_document_with_optimistic_concurrency_and_dirty_tracking()
        {
            var doc1 = new CoffeeShop();
            using (var session = theStore.OpenSession(tracking: DocumentTracking.DirtyTracking))
            {
                session.Store(doc1);
                doc1.Name = "New Name";
                session.SaveChanges();
            }
        }

FYI, Adding a SaveChanges() after Store() and before the Name update prevents the exception as a workaround, but then you are committing twice.

@jeremydmiller
Copy link
Member

@barryhagan The Id is assigned upon the call to Store(). You'd have the identity from the document you just passed in.

@barryhagan
Copy link
Contributor Author

Right, but I cannot make any other subsequent changes to the doc unless I call SaveChanges() first.

The real use case for me was to call Store() to get the Id, then save a file in a storage location where I need the doc Id (it's part of the storage path), then update the list of files on the document with the new file info. Trying to update the document after it is stored in the same session is what causes the issue.

@jeremydmiller jeremydmiller modified the milestone: 1.3 Feb 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants