public void PersistOutsideTransactionCascadedFromManyToOne()
        {
            long initialInsertCount = Sfi.Statistics.EntityInsertCount;

            using (var s = OpenSession())
            {
                MyEntity  myEntity2 = new MyEntity("test-persist-2");
                MySibling sibling   = new MySibling("test-persist-sibling-in");
                sibling.Entity = myEntity2;
                s.Persist(sibling);
                Assert.AreEqual(
                    initialInsertCount,
                    Sfi.Statistics.EntityInsertCount,
                    "persist on identity column not delayed");
                Assert.AreEqual(0, myEntity2.Id);
                s.Flush();
                Assert.AreEqual(
                    initialInsertCount + 2,
                    Sfi.Statistics.EntityInsertCount,
                    "delayed persist insert not executed on flush");
                s.Close();
            }

            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    s.Delete("from MySibling");
                    s.Delete("from MyEntity");
                    t.Commit();
                    s.Close();
                }
        }
Ejemplo n.º 2
0
        public async Task PersistOutsideTransactionCascadedFromManyToOneAsync()
        {
            long      initialInsertCount = Sfi.Statistics.EntityInsertCount;
            ISession  s         = OpenSession();
            MyEntity  myEntity2 = new MyEntity("test-persist-2");
            MySibling sibling   = new MySibling("test-persist-sibling-in");

            sibling.Entity = myEntity2;
            await(s.PersistAsync(sibling));
            Assert.AreEqual(initialInsertCount, Sfi.Statistics.EntityInsertCount, "persist on identity column not delayed");
            Assert.AreEqual(0, myEntity2.Id);
            await(s.FlushAsync());
            Assert.AreEqual(initialInsertCount + 2, Sfi.Statistics.EntityInsertCount, "delayed persist insert not executed on flush");
            s.Close();

            s = OpenSession();
            s.BeginTransaction();
            await(s.DeleteAsync("from MySibling"));
            await(s.DeleteAsync("from MyEntity"));
            await(s.Transaction.CommitAsync());
            s.Close();
        }
		public void PersistOutsideTransactionCascadedFromManyToOne()
		{
			long initialInsertCount = Sfi.Statistics.EntityInsertCount;
			ISession s = OpenSession();
			MyEntity myEntity2 = new MyEntity("test-persist-2");
			MySibling sibling = new MySibling("test-persist-sibling-in");
			sibling.Entity= myEntity2;
			s.Persist(sibling);
			Assert.AreEqual(initialInsertCount, Sfi.Statistics.EntityInsertCount, "persist on identity column not delayed");
			Assert.AreEqual(0, myEntity2.Id);
			s.Flush();
			Assert.AreEqual(initialInsertCount + 2, Sfi.Statistics.EntityInsertCount, "delayed persist insert not executed on flush");
			s.Close();

			s = OpenSession();
			s.BeginTransaction();
			s.Delete("from MySibling");
			s.Delete("from MyEntity");
			s.Transaction.Commit();
			s.Close();
		}