当前位置: 首页>>代码示例>>C#>>正文


C# DomainModel.Baz类代码示例

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


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


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