• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# DomainModel.Baz类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中NHibernate.DomainModel.Baz的典型用法代码示例。如果您正苦于以下问题:C# Baz类的具体用法?C# Baz怎么用?C# Baz使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Baz类属于NHibernate.DomainModel命名空间,在下文中一共展示了Baz类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: AddAll

        public void AddAll()
        {
            using (ISession s = OpenSession())
            {
                Foo foo1 = new Foo();
                s.Save(foo1);
                Foo foo2 = new Foo();
                s.Save(foo2);
                Foo foo3 = new Foo();
                s.Save(foo3);
                Baz baz = new Baz();
                baz.FooSet = new HashedSet();
                baz.FooSet.Add(foo1);
                s.Save(baz);
                Assert.AreEqual(1, baz.FooSet.Count);

                IList foos = new ArrayList();
                foos.Add(foo2);
                foos.Add(foo3);
                baz.FooSet.AddAll(foos);
                Assert.AreEqual(3, baz.FooSet.Count);

                s.Flush();

                // Clean up
                foreach (Foo foo in baz.FooSet)
                {
                    s.Delete(foo);
                }

                s.Delete(baz);
                s.Flush();
            }
        }
开发者ID:aistrate,项目名称:TypingPracticeTexts,代码行数:34,代码来源:FooBarTest.cs


示例2: BagOneToMany

		public void BagOneToMany()
		{
			ISession s = OpenSession();
			Baz baz = new Baz();
			IList list = new ArrayList();
			baz.Bazez = list;
			list.Add(new Baz());
			s.Save(baz);
			s.Flush();
			list.Add(new Baz());
			s.Flush();
			list.Insert(0, new Baz());
			s.Flush();
			object toDelete = list[1];
			list.RemoveAt(1);
			s.Delete(toDelete);
			s.Flush();
			s.Delete(baz);
			s.Flush();
			s.Close();
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:21,代码来源:FooBarTest.cs


示例3: CascadeDeleteDetached

		public void CascadeDeleteDetached()
		{
			Baz baz;

			using (ISession s = OpenSession())
			{
				baz = new Baz();
				IList list = new ArrayList();
				list.Add(new Fee());
				baz.Fees = list;
				s.Save(baz);
				s.Flush();
			}

			using (ISession s = OpenSession())
			{
				baz = (Baz) s.Get(typeof(Baz), baz.Code);
			}

			Assert.IsFalse(NHibernateUtil.IsInitialized(baz.Fees));

			using (ISession s = OpenSession())
			{
				s.Delete(baz);
				s.Flush();

				Assert.IsFalse(s.CreateQuery("from Fee").Enumerable().GetEnumerator().MoveNext());
			}

			using (ISession s = OpenSession())
			{
				baz = new Baz();
				IList list = new ArrayList();
				list.Add(new Fee());
				list.Add(new Fee());
				baz.Fees = list;
				s.Save(baz);
				s.Flush();
			}

			using (ISession s = OpenSession())
			{
				baz = (Baz) s.Get(typeof(Baz), baz.Code);
				NHibernateUtil.Initialize(baz.Fees);
			}

			Assert.AreEqual(2, baz.Fees.Count);

			using (ISession s = OpenSession())
			{
				s.Delete(baz);
				s.Flush();
				Assert.IsTrue(IsEmpty(s.CreateQuery("from Fee").Enumerable()));
			}
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:55,代码来源:FooBarTest.cs


示例4: ProxiesInCollections

		public void ProxiesInCollections()
		{
			ISession s = OpenSession();
			Baz baz = new Baz();
			Bar bar = new Bar();
			Bar bar2 = new Bar();
			s.Save(bar);
			object bar2id = s.Save(bar2);
			baz.FooArray = new Foo[] {bar, bar2};

			ISet hashset = new HashedSet();
			bar = new Bar();
			s.Save(bar);
			hashset.Add(bar);
			baz.FooSet = hashset;
			hashset = new HashedSet();
			hashset.Add(new Bar());
			hashset.Add(new Bar());
			baz.CascadingBars = hashset;
			ArrayList list = new ArrayList();
			list.Add(new Foo());
			baz.FooBag = list;
			object id = s.Save(baz);
			IEnumerator enumer = baz.CascadingBars.GetEnumerator();
			enumer.MoveNext();
			object bid = ((Bar) enumer.Current).Key;
			s.Flush();
			s.Close();

			s = OpenSession();
			BarProxy barprox = (BarProxy) s.Load(typeof(Bar), bid);
			BarProxy bar2prox = (BarProxy) s.Load(typeof(Bar), bar2id);
			Assert.IsTrue(bar2prox is INHibernateProxy);
			Assert.IsTrue(barprox is INHibernateProxy);
			baz = (Baz) s.Load(typeof(Baz), id);
			enumer = baz.CascadingBars.GetEnumerator();
			enumer.MoveNext();
			BarProxy b1 = (BarProxy) enumer.Current;
			enumer.MoveNext();
			BarProxy b2 = (BarProxy) enumer.Current;
			Assert.IsTrue(
				(b1 == barprox && !(b2 is INHibernateProxy))
				|| (b2 == barprox && !(b1 is INHibernateProxy))); //one-to-many
			Assert.IsTrue(baz.FooArray[0] is INHibernateProxy); //many-to-many
			Assert.AreEqual(bar2prox, baz.FooArray[1]);
			if (sessions.Settings.IsOuterJoinFetchEnabled)
			{
				enumer = baz.FooBag.GetEnumerator();
				enumer.MoveNext();
				Assert.IsFalse(enumer.Current is INHibernateProxy); // many-to-many outer-join="true"
			}

			enumer = baz.FooSet.GetEnumerator();
			enumer.MoveNext();
			Assert.IsFalse(enumer.Current is INHibernateProxy); //one-to-many
			s.Delete("from o in class Baz");
			s.Delete("from o in class Foo");
			s.Flush();
			s.Close();
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:60,代码来源:FooBarTest.cs


示例5: OrphanDelete

		public void OrphanDelete()
		{
			ISession s = OpenSession();
			ITransaction t = s.BeginTransaction();
			Baz baz = new Baz();
			IDictionary bars = new Hashtable();
			bars.Add(new Bar(), new object());
			bars.Add(new Bar(), new object());
			bars.Add(new Bar(), new object());
			s.Save(baz);
			t.Commit();
			s.Close();

			s = OpenSession();
			t = s.BeginTransaction();
			baz = (Baz) s.Load(typeof(Baz), baz.Code);
			IEnumerator enumer = bars.GetEnumerator();
			enumer.MoveNext();
			bars.Remove(enumer.Current);
			s.Delete(baz);
			enumer.MoveNext();
			bars.Remove(enumer.Current);
			s.Flush();

			Assert.AreEqual(0, s.CreateQuery("from Bar bar").List().Count);
			t.Commit();
			s.Close();
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:28,代码来源:FooBarTest.cs


示例6: CachedCollection

		public void CachedCollection()
		{
			ISession s = OpenSession();
			Baz baz = new Baz();
			baz.SetDefaults();
			s.Save(baz);
			s.Flush();
			s.Close();

			s = OpenSession();
			baz = (Baz) s.Load(typeof(Baz), baz.Code);
			((FooComponent) baz.TopComponents[0]).Count = 99;
			s.Flush();
			s.Close();

			s = OpenSession();
			baz = (Baz) s.Load(typeof(Baz), baz.Code);
			Assert.AreEqual(99, ((FooComponent) baz.TopComponents[0]).Count);
			s.Delete(baz);
			s.Flush();
			s.Close();
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:22,代码来源:FooBarTest.cs


示例7: ArraysOfTimes

		public void ArraysOfTimes()
		{
			Baz baz;

			using (ISession s = OpenSession())
			{
				baz = new Baz();
				s.Save(baz);
				baz.SetDefaults();
				s.Flush();
			}

			using (ISession s = OpenSession())
			{
				baz.TimeArray[2] = new DateTime(123); // H2.1: new Date(123)
				baz.TimeArray[3] = new DateTime(1234); // H2.1: new java.sql.Time(1234)
				s.Update(baz); // missing in H2.1
				s.Flush();
			}

			using (ISession s = OpenSession())
			{
				baz = (Baz) s.Load(typeof(Baz), baz.Code);
				s.Delete(baz);
				s.Flush();
			}
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:27,代码来源:FooBarTest.cs


示例8: CriteriaCollection

		public void CriteriaCollection()
		{
			ISession s = OpenSession();
			Baz bb = (Baz) s.CreateCriteria(typeof(Baz)).UniqueResult();
			Baz baz = new Baz();
			s.Save(baz);
			s.Flush();
			s.Close();

			s = OpenSession();
			Baz b = (Baz) s.CreateCriteria(typeof(Baz)).UniqueResult();
			Assert.IsTrue(NHibernateUtil.IsInitialized(b.TopGlarchez));
			Assert.AreEqual(0, b.TopGlarchez.Count);
			s.Delete(b);
			s.Flush();

			s.CreateCriteria(typeof(Baz))
				.CreateCriteria("TopFoos")
				.Add(Expression.IsNotNull("id"))
				.List();

			s.CreateCriteria(typeof(Baz))
				.CreateCriteria("Foo")
				.CreateCriteria("Component.Glarch")
				.CreateCriteria("ProxySet")
				.Add(Expression.IsNotNull("id"))
				.List();

			s.Close();
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:30,代码来源:FooBarTest.cs


示例9: ComponentParent

		public void ComponentParent()
		{
			ISession s = OpenSession();
			ITransaction t = s.BeginTransaction();

			BarProxy bar = new Bar();
			bar.Component = new FooComponent();
			Baz baz = new Baz();
			baz.Components = new FooComponent[] {new FooComponent(), new FooComponent()};
			s.Save(bar);
			s.Save(baz);
			t.Commit();
			s.Close();

			s = OpenSession();
			t = s.BeginTransaction();

			bar = (BarProxy) s.Load(typeof(Bar), bar.Key);
			s.Load(baz, baz.Code);

			Assert.AreEqual(bar, bar.BarComponent.Parent);
			Assert.IsTrue(baz.Components[0].Baz == baz && baz.Components[1].Baz == baz);

			s.Delete(baz);
			s.Delete(bar);

			t.Commit();
			s.Close();
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:29,代码来源:FooBarTest.cs


示例10: CollectionWhere

		public void CollectionWhere()
		{
			Foo foo1 = new Foo();
			Foo foo2 = new Foo();
			Baz baz = new Baz();
			Foo[] arr = new Foo[10];
			arr[0] = foo1;
			arr[9] = foo2;

			ISession s = OpenSession();
			s.Save(foo1);
			s.Save(foo2);
			baz.FooArray = arr;
			s.Save(baz);
			s.Flush();
			s.Close();

			s = OpenSession();
			baz = (Baz) s.Load(typeof(Baz), baz.Code);
			Assert.AreEqual(1, baz.FooArray.Length);
			Assert.AreEqual(1, s.CreateQuery("from Baz baz join baz.FooArray foo").List().Count);
			Assert.AreEqual(2, s.CreateQuery("from Foo foo").List().Count);
			Assert.AreEqual(1, s.CreateFilter(baz.FooArray, "").List().Count);

			s.Delete("from Foo foo");
			s.Delete(baz);

			IDbCommand deleteCmd = s.Connection.CreateCommand();
			deleteCmd.CommandText = "delete from FooArray where id_='" + baz.Code + "' and i>=8";
			deleteCmd.CommandType = CommandType.Text;
			int rows = deleteCmd.ExecuteNonQuery();
			Assert.AreEqual(1, rows);

			s.Flush();
			s.Close();
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:36,代码来源:FooBarTest.cs


示例11: NamedParams

		public void NamedParams()
		{
			Bar bar = new Bar();
			Bar bar2 = new Bar();
			bar.Name = "Bar";
			bar2.Name = "Bar Two";
			Baz baz = new Baz();
			baz.CascadingBars = new HashedSet();
			baz.CascadingBars.Add(bar);
			bar.Baz = baz;

			ISession s = OpenSession();
			ITransaction txn = s.BeginTransaction();
			s.Save(baz);
			s.Save(bar2);

			IList list =
				s.CreateQuery("from Bar bar left join bar.Baz baz left join baz.CascadingBars b where bar.Name like 'Bar %'").List();
			object row = list[0];
			Assert.IsTrue(row is object[] && ((object[]) row).Length == 3);

			IQuery q = s.CreateQuery(
				"select bar, b " +
				"from Bar bar " +
				"left join bar.Baz baz left join baz.CascadingBars b " +
				"where (bar.Name in (:nameList) or bar.Name in (:nameList)) and bar.String = :stringVal");

			IList nameList = new ArrayList();
			nameList.Add("bar");
			nameList.Add("Bar");
			nameList.Add("Bar Two");
			q.SetParameterList("nameList", nameList);
			q.SetParameter("stringVal", "a string");
			list = q.List();
			// a check for SAPDialect here
			Assert.AreEqual(2, list.Count);

			q = s.CreateQuery(
				"select bar, b " +
				"from Bar bar " +
				"inner join bar.Baz baz inner join baz.CascadingBars b " +
				"where bar.Name like 'Bar%'");
			list = q.List();
			Assert.AreEqual(1, list.Count);

			q = s.CreateQuery(
				"select bar, b " +
				"from Bar bar " +
				"left join bar.Baz baz left join baz.CascadingBars b " +
				"where bar.Name like :name and b.Name like :name");

			// add a check for HSQLDialect
			q.SetString("name", "Bar%");
			list = q.List();
			Assert.AreEqual(1, list.Count);

			s.Delete(baz);
			s.Delete(bar2);
			txn.Commit();
			s.Close();
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:61,代码来源:FooBarTest.cs


示例12: SaveAddDelete

		public void SaveAddDelete()
		{
			ISession s = OpenSession();
			Baz baz = new Baz();
			ISet bars = new HashedSet();
			baz.CascadingBars = bars;
			s.Save(baz);
			s.Flush();

			baz.CascadingBars.Add(new Bar());
			s.Delete(baz);
			s.Flush();
			s.Close();
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:14,代码来源:FooBarTest.cs


示例13: IdBag

		public void IdBag()
		{
			ISession s = OpenSession();
			Baz baz = new Baz();
			s.Save(baz);

			IList l = new ArrayList();
			IList l2 = new ArrayList();

			baz.IdFooBag = l;
			baz.ByteBag = l2;

			l.Add(new Foo());
			l.Add(new Bar());

			byte[] bytes = GetBytes("ffo");
			l2.Add(bytes);
			l2.Add(GetBytes("foo"));
			s.Flush();

			l.Add(new Foo());
			l.Add(new Bar());
			l2.Add(GetBytes("bar"));
			s.Flush();

			object removedObject = l[3];
			l.RemoveAt(3);
			s.Delete(removedObject);

			bytes[1] = Convert.ToByte('o');
			s.Flush();
			s.Close();

			s = OpenSession();
			baz = (Baz) s.Load(typeof(Baz), baz.Code);
			Assert.AreEqual(3, baz.IdFooBag.Count);
			Assert.AreEqual(3, baz.ByteBag.Count);
			bytes = GetBytes("foobar");

			foreach (object obj in baz.IdFooBag)
			{
				s.Delete(obj);
			}
			baz.IdFooBag = null;
			baz.ByteBag.Add(bytes);
			baz.ByteBag.Add(bytes);
			s.Flush();
			s.Close();

			s = OpenSession();
			baz = (Baz) s.Load(typeof(Baz), baz.Code);
			Assert.AreEqual(0, baz.IdFooBag.Count);
			Assert.AreEqual(5, baz.ByteBag.Count);
			s.Delete(baz);
			s.Flush();
			s.Close();
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:57,代码来源:FooBarTest.cs


示例14: ManyToManyBag

		public void ManyToManyBag()
		{
			ISession s = OpenSession();
			Baz baz = new Baz();
			object id = s.Save(baz);
			s.Flush();
			s.Close();

			s = OpenSession();
			baz = (Baz) s.Load(typeof(Baz), id);
			baz.FooBag.Add(new Foo());
			s.Flush();
			s.Close();

			s = OpenSession();
			baz = (Baz) s.Load(typeof(Baz), id);
			Assert.IsFalse(NHibernateUtil.IsInitialized(baz.FooBag));
			Assert.AreEqual(1, baz.FooBag.Count);

			Assert.IsTrue(NHibernateUtil.IsInitialized(baz.FooBag[0]));
			s.Delete(baz);
			s.Flush();
			s.Close();
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:24,代码来源:FooBarTest.cs


示例15: QueryLockMode

		public void QueryLockMode()
		{
			ISession s = OpenSession();
			ITransaction tx = s.BeginTransaction();

			Bar bar = new Bar();
			Assert.IsNull(bar.Bytes);
			s.Save(bar);
			Assert.IsNotNull(bar.Bytes);
			s.Flush();
			Assert.IsNotNull(bar.Bytes);

			bar.String = "changed";
			Baz baz = new Baz();
			baz.Foo = bar;
			s.Save(baz);
			Assert.IsNotNull(bar.Bytes);

			IQuery q = s.CreateQuery("from Foo foo, Bar bar");
			q.SetLockMode("bar", LockMode.Upgrade);
			object[] result = (object[]) q.List()[0];
			Assert.IsNotNull(bar.Bytes);

			object b = result[0];

			Assert.IsTrue(s.GetCurrentLockMode(b) == LockMode.Write && s.GetCurrentLockMode(result[1]) == LockMode.Write);
			tx.Commit();
			Assert.IsNotNull(bar.Bytes);
			s.Disconnect();

			s.Reconnect();
			tx = s.BeginTransaction();
			Assert.IsNotNull(bar.Bytes);

			Assert.AreEqual(LockMode.None, s.GetCurrentLockMode(b));
			Assert.IsNotNull(bar.Bytes);
			s.CreateQuery("from Foo foo").List();
			Assert.IsNotNull(bar.Bytes);
			Assert.AreEqual(LockMode.None, s.GetCurrentLockMode(b));
			q = s.CreateQuery("from Foo foo");
			q.SetLockMode("foo", LockMode.Read);
			q.List();

			Assert.AreEqual(LockMode.Read, s.GetCurrentLockMode(b));
			s.Evict(baz);

			tx.Commit();
			s.Disconnect();

			s.Reconnect();
			tx = s.BeginTransaction();

			Assert.AreEqual(LockMode.None, s.GetCurrentLockMode(b));
			s.Delete(s.Load(typeof(Baz), baz.Code));
			Assert.AreEqual(LockMode.None, s.GetCurrentLockMode(b));

			tx.Commit();
			s.Close();

			s = OpenSession();
			tx = s.BeginTransaction();
			q = s.CreateQuery("from Foo foo, Bar bar, Bar bar2");
			q.SetLockMode("bar", LockMode.Upgrade);
			q.SetLockMode("bar2", LockMode.Read);
			result = (object[]) q.List()[0];

			Assert.IsTrue(s.GetCurrentLockMode(result[0]) == LockMode.Upgrade &&
			              s.GetCurrentLockMode(result[1]) == LockMode.Upgrade);
			s.Delete(result[0]);
			tx.Commit();
			s.Close();
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:72,代码来源:FooBarTest.cs


示例16: RemoveContains

		public void RemoveContains()
		{
			ISession s = OpenSession();
			Baz baz = new Baz();
			baz.SetDefaults();
			s.Save(baz);
			s.Flush();

			Assert.IsTrue(s.Contains(baz));

			s.Evict(baz);
			Assert.IsFalse(s.Contains(baz), "baz should have been evicted");

			Baz baz2 = (Baz) s.Load(typeof(Baz), baz.Code);
			Assert.IsFalse(baz == baz2, "should be different objects because Baz not contained in Session");

			s.Delete(baz2);
			s.Flush();
			s.Close();
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:20,代码来源:FooBarTest.cs


示例17: Reachability

		public void Reachability()
		{
			// first for unkeyed collections
			ISession s = OpenSession();
			Baz baz1 = new Baz();
			s.Save(baz1);
			Baz baz2 = new Baz();
			s.Save(baz2);
			baz1.IntArray = new int[] {1, 2, 3, 4};
			baz1.FooSet = new HashedSet();
			Foo foo = new Foo();
			s.Save(foo);
			baz1.FooSet.Add(foo);
			s.Flush();
			s.Close();

			s = OpenSession();
			baz2 = (Baz) s.Load(typeof(Baz), baz2.Code);
			baz1 = (Baz) s.Load(typeof(Baz), baz1.Code);
			baz2.FooSet = baz1.FooSet;
			baz1.FooSet = null;
			baz2.IntArray = baz1.IntArray;
			baz1.IntArray = null;
			s.Flush();
			s.Close();

			s = OpenSession();
			baz2 = (Baz) s.Load(typeof(Baz), baz2.Code);
			baz1 = (Baz) s.Load(typeof(Baz), baz1.Code);
			Assert.AreEqual(4, baz2.IntArray.Length, "unkeyed reachability - baz2.IntArray");
			Assert.AreEqual(1, baz2.FooSet.Count, "unkeyed reachability - baz2.FooSet");
			Assert.AreEqual(0, baz1.IntArray.Length, "unkeyed reachability - baz1.IntArray");
			Assert.AreEqual(0, baz1.FooSet.Count, "unkeyed reachability - baz1.FooSet");

			foreach (object obj in baz2.FooSet)
			{
				s.Delete((FooProxy) obj);
			}

			s.Delete(baz1);
			s.Delete(baz2);
			s.Flush();
			s.Close();

			// now for collections of collections
			s = OpenSession();
			baz1 = new Baz();
			s.Save(baz1);
			baz2 = new Baz();
			s.Save(baz2);
			s.Flush();
			s.Close();

			s = OpenSession();
			baz2 = (Baz) s.Load(typeof(Baz), baz2.Code);
			baz1 = (Baz) s.Load(typeof(Baz), baz1.Code);
			s.Flush();
			s.Close();

			s = OpenSession();
			baz2 = (Baz) s.Load(typeof(Baz), baz2.Code);
			s.Flush();
			s.Close();

			s = OpenSession();
			baz2 = (Baz) s.Load(typeof(Baz), baz2.Code);
			baz1 = (Baz) s.Load(typeof(Baz), baz1.Code);
			s.Delete(baz1);
			s.Delete(baz2);
			s.Flush();
			s.Close();

			// now for keyed collections
			s = OpenSession();
			baz1 = new Baz();
			s.Save(baz1);
			baz2 = new Baz();
			s.Save(baz2);
			Foo foo1 = new Foo();
			Foo foo2 = new Foo();

			s.Save(foo1);
			s.Save(foo2);
			baz1.FooArray = new Foo[] {foo1, null, foo2};
			baz1.StringDateMap = new Hashtable();
			baz1.StringDateMap["today"] = DateTime.Today;
			baz1.StringDateMap["tomm"] = new DateTime(DateTime.Today.Ticks + (new TimeSpan(1, 0, 0, 0, 0)).Ticks);
			s.Flush();
			s.Close();

			s = OpenSession();
			baz2 = (Baz) s.Load(typeof(Baz), baz2.Code);
			baz1 = (Baz) s.Load(typeof(Baz), baz1.Code);
			baz2.FooArray = baz1.FooArray;
			baz1.FooArray = null;
			baz2.StringDateMap = baz1.StringDateMap;
			baz1.StringDateMap = null;
			s.Flush();
			s.Close();

//.........这里部分代码省略.........
开发者ID:remcoros,项目名称:nhibernate,代码行数:101,代码来源:FooBarTest.cs


示例18: CollectionCache

		public void CollectionCache()
		{
			ISession s = OpenSession();
			Baz baz = new Baz();
			baz.SetDefaults();
			s.Save(baz);
			s.Flush();
			s.Close();

			s = OpenSession();
			s.Load(typeof(Baz), baz.Code);
			s.Flush();
			s.Close();

			s = OpenSession();
			baz = (Baz) s.Load(typeof(Baz), baz.Code);
			s.Delete(baz);
			s.Flush();
			s.Close();
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:20,代码来源:FooBarTest.cs


示例19: Query

		public void Query()
		{
			ISession s = OpenSession();
			ITransaction txn = s.BeginTransaction();
			Foo foo = new Foo();
			s.Save(foo);
			Foo foo2 = new Foo();
			s.Save(foo2);
			foo.TheFoo = foo2;

			IList list = s.CreateQuery("from Foo foo inner join fetch foo.TheFoo").List();
			Foo foof = (Foo) list[0];
			Assert.IsTrue(NHibernateUtil.IsInitialized(foof.TheFoo));

			list = s.CreateQuery("from Baz baz left outer join fetch baz.FooToGlarch").List();

			list = s.CreateQuery("select foo, bar from Foo foo left outer join foo.TheFoo bar where foo = ?")
				.SetEntity(0, foo).List();


			object[] row1 = (object[]) list[0];
			Assert.IsTrue(row1[0] == foo && row1[1] == foo2);

			s.CreateQuery("select foo.TheFoo.TheFoo.String from foo in class Foo where foo.TheFoo = 'bar'").List();
			s.CreateQuery("select foo.TheFoo.TheFoo.TheFoo.String from foo in class Foo where foo.TheFoo.TheFoo = 'bar'").List();
			s.CreateQuery("select foo.TheFoo.TheFoo.String from foo in class Foo where foo.TheFoo.TheFoo.TheFoo.String = 'bar'").
				List();
			//			if( !( dialect is Dialect.HSQLDialect ) ) 
			//			{
			s.CreateQuery("select foo.String from foo in class Foo where foo.TheFoo.TheFoo.TheFoo = foo.TheFoo.TheFoo").List();
			//			}
			s.CreateQuery(
				"select foo.String from foo in class Foo where foo.TheFoo.TheFoo = 'bar' and foo.TheFoo.TheFoo.TheFoo = 'baz'").List
				();
			s.CreateQuery(
				"select foo.String from foo in class Foo where foo.TheFoo.TheFoo.TheFoo.String = 'a' and foo.TheFoo.String = 'b'").
				List();

			s.CreateQuery("from bar in class Bar, foo in elements(bar.Baz.FooArray)").List();

			if (Dialect is DB2Dialect)
			{
				s.CreateQuery("from foo in class Foo where lower( foo.TheFoo.String ) = 'foo'").List();
				s.CreateQuery("from foo in class Foo where lower( (foo.TheFoo.String || 'foo') || 'bar' ) = 'foo'").List();
				s.CreateQuery("from foo in class Foo where repeat( (foo.TheFoo.STring || 'foo') || 'bar', 2 ) = 'foo'").List();
				s.CreateQuery(
					"From foo in class Bar where foo.TheFoo.Integer is not null and repeat( (foo.TheFoo.String || 'foo') || 'bar', (5+5)/2 ) = 'foo'")
					.List();
				s.CreateQuery(
					"From foo in class Bar where foo.TheFoo.Integer is not null or repeat( (foo.TheFoo.String || 'foo') || 'bar', (5+5)/2 ) = 'foo'")
					.List();
			}

			if ((Dialect is SybaseDialect) || (Dialect is MsSql2000Dialect))
			{
				s.CreateQuery("select baz from Baz as baz join baz.FooArray foo group by baz order by sum(foo.Float)").Enumerable();
			}

			s.CreateQuery("from Foo as foo where foo.Component.Glarch.Name is not null").List();
			s.CreateQuery("from Foo as foo left outer join foo.Component.Glarch as glarch where glarch.Name = 'foo'").List();

			list = s.CreateQuery("from Foo").List();
			Assert.AreEqual(2, list.Count);
			Assert.IsTrue(list[0] is FooProxy);
			list = s.CreateQuery("from Foo foo left outer join foo.TheFoo").List();
			Assert.AreEqual(2, list.Count);
			Assert.IsTrue(((object[]) list[0])[0] is FooProxy);

			s.CreateQuery("From Foo, Bar").List();
			s.CreateQuery("from Baz baz left join baz.FooToGlarch, Bar bar join bar.TheFoo").List();
			s.CreateQuery("from Baz baz left join baz.FooToGlarch join baz.FooSet").List();
			s.CreateQuery("from Baz baz left join baz.FooToGlarch join fetch baz.FooSet foo left join fetch foo.TheFoo").List();

			list =
				s.CreateQuery(
					"from foo in class NHibernate.DomainModel.Foo where foo.String='osama bin laden' and foo.Boolean = true order by foo.String asc, foo.Component.Count desc")
					.List();
			Assert.AreEqual(0, list.Count, "empty query");
			IEnumerable enumerable =
				s.CreateQuery(
					"from foo in class NHibernate.DomainModel.Foo where foo.String='osama bin laden' order by foo.String asc, foo.Component.Count desc")
					.Enumerable();
			Assert.IsTrue(IsEmpty(enumerable), "empty enumerator");

			list = s.CreateQuery("select foo.TheFoo from foo in class NHibernate.DomainModel.Foo").List();
			Assert.AreEqual(1, list.Count, "query");
			Assert.AreEqual(foo.TheFoo, list[0], "returned object");
			foo.TheFoo.TheFoo = foo;
			foo.String = "fizard";

			if (Dialect.SupportsSubSelects)
			{
				if (!(Dialect is FirebirdDialect))
				{
					if (IsClassicParser)
					{
						list =
								s.CreateQuery("from foo in class NHibernate.DomainModel.Foo where ? = some foo.Component.ImportantDates.elements")
										.SetDateTime(0, DateTime.Today).List();

//.........这里部分代码省略.........
开发者ID:remcoros,项目名称:nhibernate,代码行数:101,代码来源:FooBarTest.cs


示例20: DereferenceLazyCollection

		public void DereferenceLazyCollection()
		{
			string fooKey;
			string bazCode;

			using (ISession s = OpenSession())
			{
				Baz baz = new Baz();
				baz.FooSet = new HashedSet();
				Foo foo = new Foo();
				baz.FooSet.Add(foo);
				s.Save(foo);
				s.Save(baz);
				foo.Bytes = GetBytes("foobar");
				s.Flush();

				fooKey = foo.Key;
				bazCode = baz.Code;
			}

			using (ISession s = OpenSession())
			{
				Foo foo = (Foo) s.Get(typeof(Foo), fooKey);
				Assert.IsTrue(NHibernateUtil.IsInitialized(foo.Bytes));

				// H2.1 has 6 here, but we are using Unicode
				Assert.AreEqual(12, foo.Bytes.Length);

				Baz baz = (Baz) s.Get(typeof(Baz), bazCode);
				Assert.AreEqual(1, baz.FooSet.Count);
				s.Flush();
			}

			sessions.EvictCollection("NHibernate.DomainModel.Baz.FooSet");

			using (ISession s = OpenSession())
			{
				Baz baz = (Baz) s.Get(typeof(Baz), bazCode);
				Assert.IsFalse(NHibernateUtil.IsInitialized(baz.FooSet));
				baz.FooSet = null;
				s.Flush();
			}

			using (ISession s = OpenSession())
			{
				Foo foo = (Foo) s.Get(typeof(Foo), fooKey);
				Assert.AreEqual(12, foo.Bytes.Length);
				Baz baz = (Baz) s.Get(typeof(Baz), bazCode);

				Assert.IsFalse(NHibernateUtil.IsInitialized(baz.FooSet));
				Assert.AreEqual(0, baz.FooSet.Count);
				s.Delete(baz);
				s.Delete(foo);
				s.Flush();
			}
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:56,代码来源:FooBarTest.cs



注:本文中的NHibernate.DomainModel.Baz类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# DomainModel.Category类代码示例发布时间:2022-05-26
下一篇:
C# DomainModel.Bar类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap