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


C# DomainModel.Glarch类代码示例

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


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

示例1: ObjectType

		public void ObjectType()
		{
			object gid;

			using (ISession s = OpenSession())
			{
				GlarchProxy g = new Glarch();
				Foo foo = new Foo();
				g.Any = foo;
				gid = s.Save(g);
				s.Save(foo);
				s.Flush();
			}

			using (ISession s = OpenSession())
			{
				GlarchProxy g = (GlarchProxy) s.Load(typeof(Glarch), gid);
				Assert.IsNotNull(g.Any);
				Assert.IsTrue(g.Any is FooProxy);
				s.Delete(g.Any);
				s.Delete(g);
				s.Flush();
			}
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:24,代码来源:FooBarTest.cs

示例2: ForCertain

		public void ForCertain()
		{
			Glarch g = new Glarch();
			Glarch g2 = new Glarch();
			IList strings = new ArrayList();
			strings.Add("foo");
			g2.Strings = strings;

			object gid, g2id;

			using (ISession s = OpenSession())
			{
				using (ITransaction t = s.BeginTransaction())
				{
					gid = s.Save(g);
					g2id = s.Save(g2);
					t.Commit();

					// Versions are initialized to 1 in NH.
					Assert.AreEqual(1, g.Version);
					Assert.AreEqual(1, g2.Version);
				}
			}

			using (ISession s = OpenSession())
			{
				using (ITransaction t = s.BeginTransaction())
				{
					g = (Glarch) s.Get(typeof(Glarch), gid);
					g2 = (Glarch) s.Get(typeof(Glarch), g2id);
					Assert.AreEqual(1, g2.Strings.Count);

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

示例3: NoForeignKeyViolations

		public void NoForeignKeyViolations()
		{
			ISession s = OpenSession();
			Glarch g1 = new Glarch();
			Glarch g2 = new Glarch();
			g1.Next = g2;
			g2.Next = g1;
			s.Save(g1);
			s.Save(g2);
			s.Flush();
			s.Close();

			s = OpenSession();
			IList l = s.CreateQuery("from g in class NHibernate.DomainModel.Glarch where g.Next is not null").List();
			s.Delete(l[0]);
			s.Delete(l[1]);
			s.Flush();
			s.Close();
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:19,代码来源:FooBarTest.cs

示例4: ProxyArray

		public void ProxyArray()
		{
			ISession s = OpenSession();
			GlarchProxy g = new Glarch();
			Glarch g1 = new Glarch();
			Glarch g2 = new Glarch();
			g.ProxyArray = new GlarchProxy[] {g1, g2};
			Glarch g3 = new Glarch();
			s.Save(g3);
			g2.ProxyArray = new GlarchProxy[] {null, g3, g};

			ISet hashset = new HashedSet();
			hashset.Add(g1);
			hashset.Add(g2);
			g.ProxySet = hashset;
			s.Save(g);
			s.Save(g1);
			s.Save(g2);
			object id = s.GetIdentifier(g);
			s.Flush();
			s.Close();

			s = OpenSession();
			g = (GlarchProxy) s.Load(typeof(Glarch), id);
			Assert.AreEqual(2, g.ProxyArray.Length, "array of proxies");
			Assert.IsNotNull(g.ProxyArray[0], "array of proxies");
			Assert.IsNull(g.ProxyArray[1].ProxyArray[0], "deferred load test");
			Assert.AreEqual(g, g.ProxyArray[1].ProxyArray[2], "deferred load test");
			Assert.AreEqual(2, g.ProxySet.Count, "set of proxies");

			IEnumerator enumer = s.CreateQuery("from g in class NHibernate.DomainModel.Glarch").Enumerable().GetEnumerator();
			while (enumer.MoveNext())
			{
				s.Delete(enumer.Current);
			}

			s.Flush();
			s.Disconnect();

			// serialize the session.
			Stream stream = new MemoryStream();
			IFormatter formatter = new BinaryFormatter();
			formatter.Serialize(stream, s);

			// close the original session
			s.Close();

			// deserialize the session
			stream.Position = 0;
			s = (ISession) formatter.Deserialize(stream);
			stream.Close();

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

示例5: VersionedCollections

		public void VersionedCollections()
		{
			ISession s = OpenSession();
			GlarchProxy g = new Glarch();
			s.Save(g);
			g.ProxyArray = new GlarchProxy[] {g};
			string gid = (string) s.GetIdentifier(g);
			ArrayList list = new ArrayList();
			list.Add("foo");
			g.Strings = list;
			// <sets> in h2.0.3
			ISet hashset = new HashedSet();
			hashset.Add(g);
			g.ProxySet = hashset;
			s.Flush();
			s.Close();

			s = OpenSession();
			g = (GlarchProxy) s.Load(typeof(Glarch), gid);
			Assert.AreEqual(1, g.Strings.Count);
			Assert.AreEqual(1, g.ProxyArray.Length);
			Assert.AreEqual(1, g.ProxySet.Count);
			Assert.AreEqual(2, g.Version, "version collection before");
			s.Flush();
			s.Close();

			s = OpenSession();
			g = (GlarchProxy) s.Load(typeof(Glarch), gid);
			Assert.AreEqual("foo", g.Strings[0]);
			Assert.AreSame(g, g.ProxyArray[0]);
			IEnumerator enumer = g.ProxySet.GetEnumerator();
			enumer.MoveNext();
			Assert.AreSame(g, enumer.Current);
			Assert.AreEqual(2, g.Version, "versioned collection before");
			s.Flush();
			s.Close();

			s = OpenSession();
			g = (GlarchProxy) s.Load(typeof(Glarch), gid);
			Assert.AreEqual(2, g.Version, "versioned collection before");
			g.Strings.Add("bar");
			s.Flush();
			s.Close();

			s = OpenSession();
			g = (GlarchProxy) s.Load(typeof(Glarch), gid);
			Assert.AreEqual(3, g.Version, "versioned collection after");
			Assert.AreEqual(2, g.Strings.Count, "versioned collection after");
			g.ProxyArray = null;
			s.Flush();
			s.Close();

			s = OpenSession();
			g = (GlarchProxy) s.Load(typeof(Glarch), gid);
			Assert.AreEqual(4, g.Version, "versioned collection after");
			Assert.AreEqual(0, g.ProxyArray.Length, "version collection after");
			g.FooComponents = new ArrayList();
			g.ProxyArray = null;
			s.Flush();
			s.Close();

			s = OpenSession();
			g = (GlarchProxy) s.Load(typeof(Glarch), gid);
			Assert.AreEqual(5, g.Version, "versioned collection after");
			s.Delete(g);
			s.Flush();
			s.Close();
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:68,代码来源:FooBarTest.cs

示例6: RecursiveLoad

		public void RecursiveLoad()
		{
			// Non polymorphisc class (there is an implementation optimization
			// being tested here) - from h2.0.3 - what does that mean?
			ISession s = OpenSession();
			ITransaction txn = s.BeginTransaction();
			GlarchProxy last = new Glarch();
			s.Save(last);
			last.Order = 0;
			for (int i = 0; i < 5; i++)
			{
				GlarchProxy next = new Glarch();
				s.Save(next);
				last.Next = next;
				last = next;
				last.Order = (short) (i + 1);
			}

			IEnumerator enumer = s.CreateQuery("from g in class NHibernate.DomainModel.Glarch").Enumerable().GetEnumerator();
			while (enumer.MoveNext())
			{
				object objTemp = enumer.Current;
			}

			IList list = s.CreateQuery("from g in class NHibernate.DomainModel.Glarch").List();
			Assert.AreEqual(6, list.Count, "recursive find");
			txn.Commit();
			s.Close();

			s = OpenSession();
			txn = s.BeginTransaction();
			list = s.CreateQuery("from g in class NHibernate.DomainModel.Glarch").List();
			Assert.AreEqual(6, list.Count, "recursive iter");
			list = s.CreateQuery("from g in class NHibernate.DomainModel.Glarch where g.Next is not null").List();
			Assert.AreEqual(5, list.Count, "exclude the null next");
			txn.Commit();
			s.Close();

			s = OpenSession();
			txn = s.BeginTransaction();
			enumer =
				s.CreateQuery("from g in class NHibernate.DomainModel.Glarch order by g.Order asc").Enumerable().GetEnumerator();
			while (enumer.MoveNext())
			{
				GlarchProxy g = (GlarchProxy) enumer.Current;
				Assert.IsNotNull(g, "not null");
				// no equiv in .net - so ran a delete query
				// iter.remove();
			}

			s.Delete("from NHibernate.DomainModel.Glarch as g");
			txn.Commit();
			s.Close();

			// same thing bug using polymorphic class (no optimization possible)
			s = OpenSession();
			txn = s.BeginTransaction();
			FooProxy flast = new Bar();
			s.Save(flast);
			for (int i = 0; i < 5; i++)
			{
				FooProxy foo = new Bar();
				s.Save(foo);
				flast.TheFoo = foo;
				flast = flast.TheFoo;
				flast.String = "foo" + (i + 1);
			}

			enumer = s.CreateQuery("from foo in class NHibernate.DomainModel.Foo").Enumerable().GetEnumerator();
			while (enumer.MoveNext())
			{
				object objTemp = enumer.Current;
			}

			list = s.CreateQuery("from foo in class NHibernate.DomainModel.Foo").List();
			Assert.AreEqual(6, list.Count, "recursive find");
			txn.Commit();
			s.Close();

			s = OpenSession();
			txn = s.BeginTransaction();
			list = s.CreateQuery("from foo in class NHibernate.DomainModel.Foo").List();
			Assert.AreEqual(6, list.Count, "recursive iter");
			enumer = list.GetEnumerator();
			while (enumer.MoveNext())
			{
				Assert.IsTrue(enumer.Current is BarProxy, "polymorphic recursive load");
			}
			txn.Commit();
			s.Close();

			s = OpenSession();
			txn = s.BeginTransaction();
			enumer =
				s.CreateQuery("from foo in class NHibernate.DomainModel.Foo order by foo.String asc").Enumerable().GetEnumerator();
			string currentString = String.Empty;

			while (enumer.MoveNext())
			{
				BarProxy bar = (BarProxy) enumer.Current;
//.........这里部分代码省略.........
开发者ID:remcoros,项目名称:nhibernate,代码行数:101,代码来源:FooBarTest.cs

示例7: PersistCollections

		public void PersistCollections()
		{
			ISession s = OpenSession();
			ITransaction txn = s.BeginTransaction();
			IEnumerator enumer = s.CreateQuery("select count(*) from b in class Bar").Enumerable().GetEnumerator();
			enumer.MoveNext();
			Assert.AreEqual(0L, enumer.Current);

			Baz baz = new Baz();
			s.Save(baz);
			baz.SetDefaults();
			baz.StringArray = new string[] {"stuff"};
			ISet bars = new HashedSet();
			bars.Add(new Bar());
			baz.CascadingBars = bars;
			IDictionary sgm = new Hashtable();
			sgm["a"] = new Glarch();
			sgm["b"] = new Glarch();
			baz.StringGlarchMap = sgm;
			txn.Commit();
			s.Close();

			s = OpenSession();
			txn = s.BeginTransaction();
			baz = (Baz) ((object[]) s.CreateQuery("select baz, baz from baz in class NHibernate.DomainModel.Baz").List()[0])[1];
			Assert.AreEqual(1, baz.CascadingBars.Count, "baz.CascadingBars.Count");
			Foo foo = new Foo();
			s.Save(foo);
			Foo foo2 = new Foo();
			s.Save(foo2);
			baz.FooArray = new Foo[] {foo, foo, null, foo2};
			baz.FooSet.Add(foo);
			baz.Customs.Add(new string[] {"new", "custom"});
			baz.StringArray = null;
			baz.StringList[0] = "new value";
			baz.StringSet = new HashedSet();

			// NOTE: We put two items in the map, but expect only one to come back, because
			// of where="..." specified in the mapping for StringGlarchMap
			Assert.AreEqual(1, baz.StringGlarchMap.Count, "baz.StringGlarchMap.Count");
			IList list;

			// disable this for dbs with no subselects
			if (Dialect.SupportsSubSelects)
			{
				if (IsClassicParser)
				{
					list =
							s.CreateQuery(
									"select foo from foo in class NHibernate.DomainModel.Foo, baz in class NHibernate.DomainModel.Baz where foo in baz.FooArray.elements and 3 = some baz.IntArray.elements and 4 > all baz.IntArray.indices")
									.List();
				}
				else
				{
					list =
						s.CreateQuery(
							"select foo from foo in class NHibernate.DomainModel.Foo, baz in class NHibernate.DomainModel.Baz where foo in elements(baz.FooArray) and 3 = some elements(baz.IntArray) and 4 > all indices(baz.IntArray)")
							.List();
				}

				Assert.AreEqual(2, list.Count, "collection.elements find");
			}

			// sapdb doesn't like distinct with binary type
			//if( !(dialect is Dialect.SAPDBDialect) ) 
			//{
			if (IsClassicParser)
			{
				list =
						s.CreateQuery("select distinct foo from baz in class NHibernate.DomainModel.Baz, foo in baz.FooArray.elements").List
								();
			}
			else
			{
				list =
					s.CreateQuery("select distinct foo from baz in class NHibernate.DomainModel.Baz, foo in elements(baz.FooArray)").
						List();
			}
			Assert.AreEqual(2, list.Count, "collection.elements find");
			//}

			list = IsClassicParser
			       	? s.CreateQuery("select foo from baz in class NHibernate.DomainModel.Baz, foo in baz.FooSet.elements").List()
			       	: s.CreateQuery("select foo from baz in class NHibernate.DomainModel.Baz, foo in elements(baz.FooSet)").List();

			Assert.AreEqual(1, list.Count, "association.elements find");

			txn.Commit();
			s.Close();

			s = OpenSession();
			txn = s.BeginTransaction();
			baz = (Baz)s.CreateQuery("select baz from baz in class NHibernate.DomainModel.Baz order by baz").List()[0];
			Assert.AreEqual(4, baz.Customs.Count, "collection of custom types - added element");
			Assert.IsNotNull(baz.Customs[0], "collection of custom types - added element");
			Assert.IsNotNull(baz.Components[1].Subcomponent, "component of component in collection");
			Assert.AreSame(baz, baz.Components[1].Baz);

			IEnumerator fooSetEnumer = baz.FooSet.GetEnumerator();
			fooSetEnumer.MoveNext();
//.........这里部分代码省略.........
开发者ID:remcoros,项目名称:nhibernate,代码行数:101,代码来源:FooBarTest.cs

示例8: Versioning

		public void Versioning()
		{
			GlarchProxy g = new Glarch();
			GlarchProxy g2 = new Glarch();

			object gid, g2id;

			using (ISession s = OpenSession())
			using (ITransaction txn = s.BeginTransaction())
			{
				s.Save(g);
				s.Save(g2);
				gid = s.GetIdentifier(g);
				g2id = s.GetIdentifier(g2);
				g.Name = "glarch";
				txn.Commit();
			}

			sessions.Evict(typeof(Glarch));

			using (ISession s = OpenSession())
			using (ITransaction txn = s.BeginTransaction())
			{
				g = (GlarchProxy) s.Load(typeof(Glarch), gid);
				s.Lock(g, LockMode.Upgrade);
				g2 = (GlarchProxy) s.Load(typeof(Glarch), g2id);

				// Versions are initialized to 1 in NH (not to 0 like in Hibernate)
				Assert.AreEqual(2, g.Version, "version");
				Assert.AreEqual(2, g.DerivedVersion, "version");
				Assert.AreEqual(1, g2.Version, "version");
				g.Name = "foo";
				Assert.IsTrue(
					s.CreateQuery("from g in class Glarch where g.Version=3").List().Count == 1,
					"find by version"
					);
				g.Name = "bar";
				txn.Commit();
			}

			sessions.Evict(typeof(Glarch));

			using (ISession s = OpenSession())
			using (ITransaction txn = s.BeginTransaction())
			{
				g = (GlarchProxy) s.Load(typeof(Glarch), gid);
				g2 = (GlarchProxy) s.Load(typeof(Glarch), g2id);
				Assert.AreEqual(4, g.Version, "version");
				Assert.AreEqual(4, g.DerivedVersion, "version");
				Assert.AreEqual(1, g2.Version, "version");
				g.Next = null;
				g2.Next = g;
				s.Delete(g2);
				s.Delete(g);
				txn.Commit();
			}
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:57,代码来源:FooBarTest.cs

示例9: Custom

		public void Custom()
		{
			GlarchProxy g = new Glarch();
			Multiplicity m = new Multiplicity();
			m.count = 12;
			m.glarch = (Glarch) g;
			g.Multiple = m;

			ISession s = OpenSession();
			object gid = s.Save(g);
			s.Flush();
			s.Close();

			s = OpenSession();
			g = (Glarch) s.CreateQuery("from Glarch g where g.Multiple.glarch=g and g.Multiple.count=12").List()[0];
			Assert.IsNotNull(g.Multiple);
			Assert.AreEqual(12, g.Multiple.count);
			Assert.AreSame(g, g.Multiple.glarch);
			s.Flush();
			s.Close();

			s = OpenSession();
			g = (GlarchProxy) s.Load(typeof(Glarch), gid);
			Assert.IsNotNull(g.Multiple);
			Assert.AreEqual(12, g.Multiple.count);
			Assert.AreSame(g, g.Multiple.glarch);
			s.Delete(g);
			s.Flush();
			s.Close();
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:30,代码来源:FooBarTest.cs

示例10: Dyna

		public void Dyna()
		{
			ISession s = OpenSession();
			GlarchProxy g = new Glarch();
			g.Name = "G";
			object id = s.Save(g);
			s.Flush();
			s.Close();

			s = OpenSession();
			g = (GlarchProxy) s.Load(typeof(Glarch), id);
			Assert.AreEqual("G", g.Name);
			Assert.AreEqual("foo", g.DynaBean["foo"]);
			Assert.AreEqual(66, g.DynaBean["bar"]);

			Assert.IsFalse(g is Glarch);
			g.DynaBean["foo"] = "bar";
			s.Flush();
			s.Close();

			s = OpenSession();
			g = (GlarchProxy) s.Load(typeof(Glarch), id);
			Assert.AreEqual("bar", g.DynaBean["foo"]);
			Assert.AreEqual(66, g.DynaBean["bar"]);
			g.DynaBean = null;
			s.Flush();
			s.Close();

			s = OpenSession();
			g = (GlarchProxy) s.Load(typeof(Glarch), id);
			Assert.IsNull(g.DynaBean);
			s.Delete(g);
			s.Flush();
			s.Close();
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:35,代码来源:FooBarTest.cs

示例11: ForceOuterJoin

		public void ForceOuterJoin()
		{
			if (sessions.Settings.IsOuterJoinFetchEnabled == false)
			{
				// don't bother to run the test if we can't test it
				return;
			}

			ISession s = OpenSession();
			Glarch g = new Glarch();
			FooComponent fc = new FooComponent();
			fc.Glarch = g;
			FooProxy f = new Foo();
			FooProxy f2 = new Foo();
			f.Component = fc;
			f.TheFoo = f2;
			s.Save(f2);
			object id = s.Save(f);
			object gid = s.GetIdentifier(f.Component.Glarch);
			s.Flush();
			s.Close();

			s = OpenSession();
			f = (FooProxy) s.Load(typeof(Foo), id);
			Assert.IsFalse(NHibernateUtil.IsInitialized(f));
			Assert.IsTrue(NHibernateUtil.IsInitialized(f.Component.Glarch)); //outer-join="true"
			Assert.IsFalse(NHibernateUtil.IsInitialized(f.TheFoo)); //outer-join="auto"
			Assert.AreEqual(gid, s.GetIdentifier(f.Component.Glarch));
			s.Delete(f);
			s.Delete(f.TheFoo);
			s.Delete(f.Component.Glarch);
			s.Flush();
			s.Close();
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:34,代码来源:FooBarTest.cs

示例12: QueryCollectionOfValues

		public void QueryCollectionOfValues()
		{
			object gid;

			using (ISession s = OpenSession())
			{
				Baz baz = new Baz();
				baz.SetDefaults();
				s.Save(baz);
				Glarch g = new Glarch();
				gid = s.Save(g);

				if (Dialect.SupportsSubSelects)
				{
					s.CreateFilter(baz.FooArray, "where size(this.Bytes) > 0").List();
					s.CreateFilter(baz.FooArray, "where 0 in elements(this.Bytes)").List();
				}
				s.Flush();
			}

			using (ISession s = OpenSession())
			{
				//s.CreateQuery("from Baz baz where baz.FooSet.String = 'foo'").List();
				//s.CreateQuery("from Baz baz where baz.FooArray.String = 'foo'").List();
				//s.CreateQuery("from Baz baz where baz.FooSet.foo.String = 'foo'").List();
				//s.CreateQuery("from Baz baz join baz.FooSet.Foo foo where foo.String = 'foo'").List();
				s.CreateQuery("from Baz baz join baz.FooSet foo join foo.TheFoo.TheFoo foo2 where foo2.String = 'foo'").List();
				s.CreateQuery("from Baz baz join baz.FooArray foo join foo.TheFoo.TheFoo foo2 where foo2.String = 'foo'").List();
				s.CreateQuery("from Baz baz join baz.StringDateMap date where index(date) = 'foo'").List();
				s.CreateQuery("from Baz baz join baz.TopGlarchez g where index(g) = 'A'").List();
				s.CreateQuery("select index(g) from Baz baz join baz.TopGlarchez g").List();

				Assert.AreEqual(3, s.CreateQuery("from Baz baz left join baz.StringSet").List().Count);
				Baz baz = (Baz) s.CreateQuery("from Baz baz join baz.StringSet str where str='foo'").List()[0];
				Assert.IsFalse(NHibernateUtil.IsInitialized(baz.StringSet));
				baz = (Baz) s.CreateQuery("from Baz baz left join fetch baz.StringSet").List()[0];
				Assert.IsTrue(NHibernateUtil.IsInitialized(baz.StringSet));
				Assert.AreEqual(1, s.CreateQuery("from Baz baz join baz.StringSet string where string='foo'").List().Count);
				Assert.AreEqual(1, s.CreateQuery("from Baz baz inner join baz.Components comp where comp.Name='foo'").List().Count);
				//IList bss = s.CreateQuery("select baz, ss from Baz baz inner join baz.StringSet ss").List();
				s.CreateQuery("from Glarch g inner join g.FooComponents comp where comp.Fee is not null").List();
				s.CreateQuery("from Glarch g inner join g.FooComponents comp join comp.Fee fee where fee.Count > 0").List();
				s.CreateQuery("from Glarch g inner join g.FooComponents comp where comp.Fee.Count is not null").List();

				s.Delete(baz);
				//s.delete("from Glarch g");
				s.Delete(s.Get(typeof(Glarch), gid));
				s.Flush();
			}
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:50,代码来源:FooBarTest.cs

示例13: NonlazyCollections

		public void NonlazyCollections()
		{
			object glarchId;

			using (ISession s = OpenSession())
			{
				Glarch glarch1 = new Glarch();
				glarch1.ProxySet = new ListSet();

				Glarch glarch2 = new Glarch();
				glarch1.ProxySet.Add(glarch1);

				s.Save(glarch2);
				glarchId = s.Save(glarch1);
				s.Flush();
			}

			Glarch loadedGlarch;
			using (ISession s = OpenSession())
			{
				loadedGlarch = (Glarch) s.Get(typeof(Glarch), glarchId);
				Assert.IsTrue(NHibernateUtil.IsInitialized(loadedGlarch.ProxySet));
			}

			// ProxySet is a non-lazy collection, so this should work outside
			// a session.
			Assert.AreEqual(1, loadedGlarch.ProxySet.Count);

			using (ISession s = OpenSession())
			{
				s.Delete("from Glarch");
				s.Flush();
			}
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:34,代码来源:FooBarTest.cs

示例14: ComplexCriteria

		public void ComplexCriteria()
		{
			ISession s = OpenSession();
			ITransaction t = s.BeginTransaction();
			Baz baz = new Baz();
			s.Save(baz);
			baz.SetDefaults();
			IDictionary topGlarchez = new Hashtable();
			baz.TopGlarchez = topGlarchez;
			Glarch g1 = new Glarch();
			g1.Name = "g1";
			s.Save(g1);
			Glarch g2 = new Glarch();
			g2.Name = "g2";
			s.Save(g2);

			g1.ProxyArray = new GlarchProxy[] {g2};
			topGlarchez['1'] = g1;
			topGlarchez['2'] = g2;
			Foo foo1 = new Foo();
			Foo foo2 = new Foo();
			s.Save(foo1);
			s.Save(foo2);
			baz.FooSet.Add(foo1);
			baz.FooSet.Add(foo2);
			baz.FooArray = new FooProxy[] {foo1};

			LockMode lockMode = (Dialect is DB2Dialect) ? LockMode.Read : LockMode.Upgrade;

			ICriteria crit = s.CreateCriteria(typeof(Baz));
			crit.CreateCriteria("TopGlarchez")
				.Add(Expression.IsNotNull("Name"))
				.CreateCriteria("ProxyArray")
				.Add(Expression.EqProperty("Name", "Name"))
				.Add(Expression.Eq("Name", "g2"))
				.Add(Expression.Gt("X", -666));
			crit.CreateCriteria("FooSet")
				.Add(Expression.IsNull("Null"))
				.Add(Expression.Eq("String", "a string"))
				.Add(Expression.Lt("Integer", -665));
			crit.CreateCriteria("FooArray")
				.Add(Expression.Eq("String", "a string"))
				.SetLockMode(lockMode);

			IList list = crit.List();
			Assert.AreEqual(2, list.Count);

			s.CreateCriteria(typeof(Glarch)).SetLockMode(LockMode.Upgrade).List();
			s.CreateCriteria(typeof(Glarch)).SetLockMode(CriteriaSpecification.RootAlias, LockMode.Upgrade).List();

			g2.Name = null;
			t.Commit();
			s.Close();

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

			crit = s.CreateCriteria(typeof(Baz))
				.SetLockMode(lockMode);
			crit.CreateCriteria("TopGlarchez")
				.Add(Expression.Gt("X", -666));
			crit.CreateCriteria("FooSet")
				.Add(Expression.IsNull("Null"));
			list = crit.List();

			Assert.AreEqual(4, list.Count);
			baz = (Baz) crit.UniqueResult();
			Assert.IsTrue(NHibernateUtil.IsInitialized(baz.TopGlarchez)); //cos it is nonlazy
			Assert.IsFalse(NHibernateUtil.IsInitialized(baz.FooSet));

			//list = s.CreateCriteria(typeof( Baz ))
			//	.createCriteria("fooSet.foo.component.glarch")
			//		.Add( Expression.eq("name", "xxx") )
			//	.Add( Expression.eq("fooSet.foo.component.glarch.name", "xxx") )
			//	.list();
			//assertTrue( list.size()==0 );
			list = s.CreateCriteria(typeof(Baz))
				.CreateCriteria("FooSet")
				.CreateCriteria("TheFoo")
				.CreateCriteria("Component.Glarch")
				.Add(Expression.Eq("Name", "xxx"))
				.List();
			Assert.AreEqual(0, list.Count);

			list = s.CreateCriteria(typeof(Baz))
				.CreateAlias("FooSet", "foo")
				.CreateAlias("foo.TheFoo", "foo2")
				.SetLockMode("foo2", lockMode)
				.Add(Expression.IsNull("foo2.Component.Glarch"))
				.CreateCriteria("foo2.Component.Glarch")
				.Add(Expression.Eq("Name", "xxx"))
				.List();
			Assert.AreEqual(0, list.Count);

			t.Commit();
			s.Close();

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

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

示例15: Versioning

		public void Versioning()
		{
			GlarchProxy g = new Glarch();
			GlarchProxy g2 = new Glarch();

			object gid, g2id;

			using( ISession s = OpenSession() )
			{
				s.Save( g );
				s.Save( g2 );
				gid = s.GetIdentifier( g );
				g2id = s.GetIdentifier( g2 );
				g.Name = "glarch";
				s.Flush();
			}

			sessions.Evict( typeof( Glarch ) );

			using( ISession s = OpenSession() )
			{
				g = ( GlarchProxy ) s.Load( typeof( Glarch ), gid );
				s.Lock( g, LockMode.Upgrade );
				g2 = ( GlarchProxy ) s.Load( typeof( Glarch ), g2id );
				Assert.IsTrue( g.Version == 1, "version" );
				Assert.IsTrue( g.DerivedVersion == 1, "version" );
				Assert.IsTrue( g2.Version == 0, "version" );
				g.Name = "foo";
				Assert.IsTrue(
					s.Find( "from g in class Glarch where g.Version=2" ).Count == 1,
					"find by version"
					);
				g.Name = "bar";
				s.Flush();
			}

			sessions.Evict( typeof( Glarch ) );

			using( ISession s = OpenSession() )
			{
				g = ( GlarchProxy ) s.Load( typeof( Glarch ), gid );
				g2 = ( GlarchProxy ) s.Load( typeof( Glarch ), g2id );
				Assert.IsTrue( g.Version == 3, "version" );
				Assert.IsTrue( g.DerivedVersion == 3, "version" );
				Assert.IsTrue( g2.Version == 0, "version" );
				g.Next = null;
				g2.Next = g;
				s.Delete( g2 );
				s.Delete( g );
				s.Flush();
			}
		}
开发者ID:rcarrillopadron,项目名称:nhibernate-1.0.2.0,代码行数:52,代码来源:FooBarTest.cs


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