コード例 #1
0
		public void MergeBidiForeignKeyOneToOne()
		{
			Person p;
			Address a;
			using (ISession s = OpenSession())
			{
				using (ITransaction tx = s.BeginTransaction())
				{
					p = new Person {Name = "steve"};
					a = new Address {StreetAddress = "123 Main", City = "Austin", Country = "US", Resident = p};
					s.Persist(a);
					s.Persist(p);
					tx.Commit();
				}
			}

			ClearCounts();

			p.Address.StreetAddress = "321 Main";

			using (ISession s = OpenSession())
			{
				using (s.BeginTransaction())
				{
					p = (Person) s.Merge(p);
					s.Transaction.Commit();
				}
			}

			AssertInsertCount(0);
			AssertUpdateCount(0); // no cascade
			AssertDeleteCount(0);

			using (ISession s = OpenSession())
			{
				using (ITransaction tx = s.BeginTransaction())
				{
					s.Delete(a);
					s.Delete(p);
					tx.Commit();
				}
			}
		}
コード例 #2
0
		public void MergeBidiPrimayKeyOneToOne()
		{
			Person p;
			using (ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				p = new Person {Name = "steve"};
				new PersonalDetails {SomePersonalDetail = "I have big feet", Person = p};
				s.Persist(p);
				tx.Commit();
			}

			ClearCounts();

			p.Details.SomePersonalDetail = p.Details.SomePersonalDetail + " and big hands too";
			using (ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				p = (Person) s.Merge(p);
				tx.Commit();
			}

			AssertInsertCount(0);
			AssertUpdateCount(1);
			AssertDeleteCount(0);

			using (ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				s.Delete(p);
				tx.Commit();
			}
		}