public void PersistThenMergeInSameTxnWithTimestamp() { ISession s = OpenSession(); ITransaction tx = s.BeginTransaction(); var entity = new TimestampedEntity { Id = "test", Name = "test" }; s.Persist(entity); s.Merge(new TimestampedEntity { Id = "test", Name = "test-2" }); try { // control operation... s.SaveOrUpdate(new TimestampedEntity { Id = "test", Name = "test-3" }); Assert.Fail("saveOrUpdate() should fail here"); } catch (NonUniqueObjectException) { // expected behavior } tx.Commit(); s.Close(); }
public async Task PersistThenMergeInSameTxnWithTimestampAsync() { using (ISession s = OpenSession()) using (ITransaction tx = s.BeginTransaction()) { var entity = new TimestampedEntity { Id = "test", Name = "test" }; await(s.PersistAsync(entity)); await(s.MergeAsync(new TimestampedEntity { Id = "test", Name = "test-2" })); try { // control operation... await(s.SaveOrUpdateAsync(new TimestampedEntity { Id = "test", Name = "test-3" })); Assert.Fail("saveOrUpdate() should fail here"); } catch (NonUniqueObjectException) { // expected behavior } await(tx.CommitAsync()); } }
public void PersistThenMergeInSameTxnWithTimestamp() { ISession s = OpenSession(); ITransaction tx = s.BeginTransaction(); var entity = new TimestampedEntity {Id = "test", Name = "test"}; s.Persist(entity); s.Merge(new TimestampedEntity {Id = "test", Name = "test-2"}); try { // control operation... s.SaveOrUpdate(new TimestampedEntity {Id = "test", Name = "test-3"}); Assert.Fail("saveOrUpdate() should fail here"); } catch (NonUniqueObjectException) { // expected behavior } tx.Commit(); s.Close(); }