コード例 #1
0
		public void CollectionPointer()
		{
			ISession s = OpenSession();
			Lower ls = new Lower();
			IList<Top> list = new List<Top>();
			ls.Bag = list;
			Top simple = new Top();
			object id = s.Save(ls);
			s.Save(simple);
			s.Flush();
			list.Add(simple);
			s.Flush();
			s.Close();

			s = OpenSession();
			ls = (Lower) s.Load(typeof(Lower), id);
			Assert.AreEqual(1, ls.Bag.Count);
			s.Delete("from o in class System.Object");
			s.Flush();
			s.Close();
		}
コード例 #2
0
		public void MultiTableManyToOne()
		{
			if (Dialect is MySQLDialect)
			{
				return;
			}

			ISession s = OpenSession();
			ITransaction t = s.BeginTransaction();
			Assert.AreEqual(0, s.CreateQuery("from s in class Top").List().Count);
			Multi multi = new Multi();
			multi.ExtraProp = "extra";
			multi.Name = "name";
			Top simp = new Top();
			simp.Date = DateTime.Now;
			simp.Name = "simp";
			object mid;

			if (Dialect is MsSql2000Dialect)
			{
				mid = s.Save(multi);
			}
			else
			{
				mid = 123L;
				s.Save(multi, mid);
			}
			Lower ls = new Lower();
			ls.Other = ls;
			ls.Another = multi;
			ls.YetAnother = ls;
			ls.Name = "Less Simple";
			object id;
			if (Dialect is MsSql2000Dialect)
			{
				id = s.Save(ls);
			}
			else
			{
				id = 2L;
				s.Save(ls, id);
			}
			t.Commit();
			s.Close();

			Assert.AreSame(ls, ls.Other);
			Assert.AreSame(multi, ls.Another);
			Assert.AreSame(ls, ls.YetAnother);

			s = OpenSession();
			t = s.BeginTransaction();
			ls = (Lower) s.Load(typeof(Lower), id);
			Assert.AreSame(ls, ls.Other);
			Assert.AreSame(ls, ls.YetAnother);
			Assert.AreEqual("name", ls.Another.Name);
			Assert.IsTrue(ls.Another is Multi);
			s.Delete(ls);
			s.Delete(ls.Another);
			t.Commit();
			s.Close();
		}
コード例 #3
0
		public void OneToOne()
		{
			ISession s = OpenSession();
			Lower ls = new Lower();
			object id = s.Save(ls);
			s.Flush();
			s.Close();

			s = OpenSession();
			s.Load(typeof(Lower), id);
			s.Close();

			s = OpenSession();
			s.Delete(s.Load(typeof(Lower), id));
			s.Flush();
			s.Close();
		}
コード例 #4
0
		public void MultiTableCollections()
		{
			if (Dialect is MySQLDialect)
			{
				return;
			}

			ISession s = OpenSession();
			ITransaction t = s.BeginTransaction();
			Assert.AreEqual(0, s.CreateQuery("from s in class Top").List().Count);
			Multi multi = new Multi();
			multi.ExtraProp = "extra";
			multi.Name = "name";
			Top simp = new Top();
			simp.Date = DateTime.Now;
			simp.Name = "simp";
			object mid;
			object sid;
			if (Dialect is MsSql2000Dialect)
			{
				mid = s.Save(multi);
				sid = s.Save(simp);
			}
			else
			{
				mid = 123L;
				sid = 1234L;
				s.Save(multi, mid);
				s.Save(simp, sid);
			}
			Lower ls = new Lower();
			ls.Other = ls;
			ls.Another = ls;
			ls.YetAnother = ls;
			ls.Name = "Less Simple";
			ls.Set = new HashSet<Top> { multi, simp };

			object id;
			if (Dialect is MsSql2000Dialect)
			{
				id = s.Save(ls);
			}
			else
			{
				id = 2L;
				s.Save(ls, id);
			}
			t.Commit();
			s.Close();
			Assert.AreSame(ls, ls.Other);
			Assert.AreSame(ls, ls.Another);
			Assert.AreSame(ls, ls.YetAnother);

			s = OpenSession();
			t = s.BeginTransaction();
			ls = (Lower) s.Load(typeof(Lower), id);
			Assert.AreSame(ls, ls.Other);
			Assert.AreSame(ls, ls.Another);
			Assert.AreSame(ls, ls.YetAnother);
			Assert.AreEqual(2, ls.Set.Count);

			int foundMulti = 0;
			int foundSimple = 0;

			foreach (object obj in ls.Set)
			{
				if (obj is Top) foundSimple++;
				if (obj is Multi) foundMulti++;
			}
			Assert.AreEqual(2, foundSimple);
			Assert.AreEqual(1, foundMulti);
			Assert.AreEqual(3, s.Delete("from s in class Top"));
			t.Commit();
			s.Close();
		}