Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
asgerhallas committed Jun 18, 2024
1 parent 9b67e69 commit 2b54557
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/HybridDb/DocumentSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class DocumentSession : IDocumentSession, IAdvancedDocumentSession

DocumentTransaction enlistedTx;

bool saving = false;
bool saving;

internal DocumentSession(IDocumentStore store, DocumentMigrator migrator, DocumentTransaction tx = null)
{
Expand Down Expand Up @@ -57,7 +57,7 @@ internal DocumentSession(DocumentSession session) : this(session.DocumentStore,
deferredCommands.AddRange(session.deferredCommands);
}

public Guid CommitId { get; }
public Guid CommitId { get; private set; }

public IAdvancedDocumentSession Advanced => this;

Expand Down Expand Up @@ -153,10 +153,7 @@ public IQueryable<T> Query<T>() where T : class

public IEnumerable<T> Query<T>(SqlBuilder sql) where T : class => Transactionally(x => x.Query<T>(sql).rows);

public void Defer(DmlCommand command)
{
deferredCommands.Add(command);
}
public void Defer(DmlCommand command) => deferredCommands.Add(command);

public void Evict(object entity)
{
Expand Down Expand Up @@ -382,7 +379,17 @@ public Guid SaveChanges(bool lastWriteWins, bool forceWriteUnchangedDocument)

saving = false;

return CommitId;
var commitId = CommitId;

// We must update the CommitId upon saving. If we keep using the same session
// and change the already loaded entities, they must get a new CommmitId/Etag when we save again.
// If we did not do this, these last changes to entities could be overwriten by other actors.
// But if we are in a transaction we keep the same CommitId as we assume that rows are locked
// and no other actor can change them. We do not currently handle the case where we reuse the
// same session across multiple transactions.
CommitId = enlistedTx?.CommitId ?? Guid.NewGuid();

return commitId;
}

IDictionary<string, object> CreateProjections(ManagedEntity managedEntity) =>
Expand Down

0 comments on commit 2b54557

Please sign in to comment.