예제 #1
0
		public virtual Node AddChild(Node child)
		{
			children.Add(child);
			child.Parent = this;
			return this;
		}
예제 #2
0
		public void NoExtraUpdatesOnMergeWithCollection()
		{
			ISession s = OpenSession();
			s.BeginTransaction();
			var parent = new Node {Name = "parent"};
			var child = new Node {Name = "child"};
			parent.Children.Add(child);
			child.Parent = parent;
			s.Persist(parent);
			s.Transaction.Commit();
			s.Close();

			ClearCounts();

			// parent is now detached, but we have made no changes.  so attempt to merge it
			// into this new session; this should cause no updates...
			s = OpenSession();
			s.BeginTransaction();
			parent = (Node) s.Merge(parent);
			s.Transaction.Commit();
			s.Close();

			AssertUpdateCount(0);
			AssertInsertCount(0);

			///////////////////////////////////////////////////////////////////////
			// as a control measure, now update the node while it is detached and
			// make sure we get an update as a result...
			IEnumerator<Node> it = parent.Children.GetEnumerator();
			it.MoveNext();
			it.Current.Description = "child's new description";
			parent.Children.Add(new Node {Name = "second child"});
			s = OpenSession();
			s.BeginTransaction();
			parent = (Node) s.Merge(parent);
			s.Transaction.Commit();
			s.Close();
			AssertUpdateCount(1);
			AssertInsertCount(1);
			///////////////////////////////////////////////////////////////////////
		}
예제 #3
0
		public void MergeTree()
		{
			ClearCounts();

			ISession s = OpenSession();
			ITransaction tx = s.BeginTransaction();
			var root = new Node {Name = "root"};
			var child = new Node {Name = "child"};
			root.AddChild(child);
			s.Persist(root);
			tx.Commit();
			s.Close();

			AssertInsertCount(2);
			ClearCounts();

			root.Description = "The root node";
			child.Description = "The child node";

			var secondChild = new Node {Name = "second child"};

			root.AddChild(secondChild);

			s = OpenSession();
			tx = s.BeginTransaction();
			s.Merge(root);
			tx.Commit();
			s.Close();

			AssertInsertCount(1);
			AssertUpdateCount(2);
		}
예제 #4
0
		public void NoExtraUpdatesOnMerge()
		{
			ISession s = OpenSession();
			s.BeginTransaction();
			var node = new Node {Name = "test"};
			s.Persist(node);
			s.Transaction.Commit();
			s.Close();

			ClearCounts();

			// node is now detached, but we have made no changes.  so attempt to merge it
			// into this new session; this should cause no updates...
			s = OpenSession();
			s.BeginTransaction();
			node = (Node) s.Merge(node);
			s.Transaction.Commit();
			s.Close();

			AssertUpdateCount(0);
			AssertInsertCount(0);

			///////////////////////////////////////////////////////////////////////
			// as a control measure, now update the node while it is detached and
			// make sure we get an update as a result...
			node.Description = "new description";
			s = OpenSession();
			s.BeginTransaction();
			node = (Node) s.Merge(node);
			s.Transaction.Commit();
			s.Close();
			AssertUpdateCount(1);
			AssertInsertCount(0);
			///////////////////////////////////////////////////////////////////////
		}
예제 #5
0
		public void MergeDeepTree()
		{
			ClearCounts();

			ISession s = OpenSession();
			ITransaction tx = s.BeginTransaction();
			var root = new Node {Name = "root"};
			var child = new Node {Name = "child"};
			var grandchild = new Node {Name = "grandchild"};
			root.AddChild(child);
			child.AddChild(grandchild);
			s.Merge(root);
			tx.Commit();
			s.Close();

			AssertInsertCount(3);
			AssertUpdateCount(0);
			ClearCounts();

			grandchild.Description = "the grand child";
			var grandchild2 = new Node {Name = "grandchild2"};
			child.AddChild(grandchild2);

			s = OpenSession();
			tx = s.BeginTransaction();
			s.Merge(root);
			tx.Commit();
			s.Close();

			AssertInsertCount(1);
			AssertUpdateCount(1);
			ClearCounts();

			var child2 = new Node {Name = "child2"};
			var grandchild3 = new Node {Name = "grandchild3"};
			child2.AddChild(grandchild3);
			root.AddChild(child2);

			s = OpenSession();
			tx = s.BeginTransaction();
			s.Merge(root);
			tx.Commit();
			s.Close();

			AssertInsertCount(2);
			AssertUpdateCount(0);
			ClearCounts();

			s = OpenSession();
			tx = s.BeginTransaction();
			s.Delete(grandchild);
			s.Delete(grandchild2);
			s.Delete(grandchild3);
			s.Delete(child);
			s.Delete(child2);
			s.Delete(root);
			tx.Commit();
			s.Close();
		}