You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
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):
FYI, Adding a SaveChanges() after Store() and before the Name update prevents the exception as a workaround, but then you are committing twice.
The text was updated successfully, but these errors were encountered: