Esempio n. 1
0
        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();
        }
Esempio n. 2
0
        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());
                }
        }
Esempio n. 3
0
		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();
		}