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


C# Baz.SetDefaults方法代码示例

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


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

示例1: Copy

		public void Copy()
		{
			Baz baz = new Baz();
			baz.SetDefaults();

			using (ISession s = OpenSession())
			{
				Baz persistentBaz = new Baz();
				s.Save(persistentBaz);
				s.Flush();

				baz.Code = persistentBaz.Code;
			}

			using (ISession s = OpenSession())
			{
				Baz persistentBaz = s.Get(typeof(Baz), baz.Code) as Baz;
				Baz copiedBaz = (Baz) s.SaveOrUpdateCopy(baz);
				Assert.AreSame(persistentBaz, copiedBaz);

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

示例2: AutoFlushCollections

		public void AutoFlushCollections()
		{
			ISession s = OpenSession();
			ITransaction tx = s.BeginTransaction();
			Baz baz = new Baz();
			baz.SetDefaults();
			s.Save(baz);
			tx.Commit();
			s.Close();

			s = OpenSession();
			tx = s.BeginTransaction();
			baz = (Baz) s.Load(typeof(Baz), baz.Code);
			baz.StringArray[0] = "bark";

			IEnumerator e;

			if (IsClassicParser)
			{
				e =
					s.CreateQuery("select baz.StringArray.elements from baz in class NHibernate.DomainModel.Baz").Enumerable().
						GetEnumerator();
			}
			else
			{
				e =
					s.CreateQuery("select elements(baz.StringArray) from baz in class NHibernate.DomainModel.Baz").Enumerable().
						GetEnumerator();
			}

			bool found = false;
			while (e.MoveNext())
			{
				if ("bark".Equals(e.Current))
				{
					found = true;
				}
			}
			Assert.IsTrue(found);
			baz.StringArray = null;

			if (IsClassicParser)
			{
				e = s.CreateQuery("select distinct baz.StringArray.elements from baz in class NHibernate.DomainModel.Baz")
						 .Enumerable()
						 .GetEnumerator();
			}
			else
			{
				e =
					s.CreateQuery("select distinct elements(baz.StringArray) from baz in class NHibernate.DomainModel.Baz").Enumerable()
						.GetEnumerator();
			}
			Assert.IsFalse(e.MoveNext());
			baz.StringArray = new string[] {"foo", "bar"};

			if (IsClassicParser)
			{
				e = s.CreateQuery("select baz.StringArray.elements from baz in class NHibernate.DomainModel.Baz")
						 .Enumerable()
						 .GetEnumerator();
			}
			else
			{
				e =
					s.CreateQuery("select elements(baz.StringArray) from baz in class NHibernate.DomainModel.Baz").Enumerable().
						GetEnumerator();
			}
			Assert.IsTrue(e.MoveNext());

			Foo foo = new Foo();
			s.Save(foo);
			s.Flush();
			baz.FooArray = new Foo[] {foo};

			if (IsClassicParser)
			{
				e = s.CreateQuery("select foo from baz in class NHibernate.DomainModel.Baz, foo in baz.FooArray.elements")
						 .Enumerable()
						 .GetEnumerator();
			}
			else
			{
				e =
					s.CreateQuery("select foo from baz in class NHibernate.DomainModel.Baz, foo in elements(baz.FooArray)").Enumerable()
						.GetEnumerator();
			}
			found = false;
			while (e.MoveNext())
			{
				if (foo == e.Current)
				{
					found = true;
				}
			}
			Assert.IsTrue(found);

			baz.FooArray[0] = null;

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

示例3: 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

示例4: Query


//.........这里部分代码省略.........
				enumerable =
					s.CreateQuery("select max(elements(foo.Component.ImportantDates)) from foo in class Foo group by foo.id").
						Enumerable();
			}
			IEnumerator enumerator = enumerable.GetEnumerator();

			Assert.IsTrue(enumerator.MoveNext());
			Assert.IsTrue(enumerator.Current is DateTime);

			list = s.CreateQuery(
				"select foo.TheFoo.TheFoo.TheFoo from foo in class Foo, foo2 in class Foo where"
				+ " foo = foo2.TheFoo and not not ( not foo.String='fizard' )"
				+ " and foo2.String between 'a' and (foo.TheFoo.String)"
				+ (Dialect is SQLiteDialect
				   	? " and ( foo2.String in ( 'fiz', 'blah') or 1=1 )"
				   	: " and ( foo2.String in ( 'fiz', 'blah', foo.TheFoo.String, foo.String, foo2.String ) )")
				).List();
			Assert.AreEqual(1, list.Count, "complex query");
			Assert.AreSame(foo, list[0], "returned object");

			foo.String = "from BoogieDown  -tinsel town  [email protected]#$^&*())";

			list = s.CreateQuery("from foo in class Foo where foo.String='from BoogieDown  -tinsel town  [email protected]#$^&*())'").List();
			Assert.AreEqual(1, list.Count, "single quotes");

			list = s.CreateQuery("from foo in class Foo where not foo.String='foo''bar'").List();
			Assert.AreEqual(2, list.Count, "single quotes");

			list = s.CreateQuery("from foo in class Foo where foo.Component.Glarch.Next is null").List();
			Assert.AreEqual(2, list.Count, "query association in component");

			Bar bar = new Bar();
			Baz baz = new Baz();
			baz.SetDefaults();
			bar.Baz = baz;
			baz.ManyToAny = new ArrayList();
			baz.ManyToAny.Add(bar);
			baz.ManyToAny.Add(foo);
			s.Save(bar);
			s.Save(baz);
			list =
				s.CreateQuery(" from bar in class Bar where bar.Baz.Count=667 and bar.Baz.Count!=123 and not bar.Baz.Name='1-E-1'").
					List();
			Assert.AreEqual(1, list.Count, "query many-to-one");
			list = s.CreateQuery(" from i in class Bar where i.Baz.Name='Bazza'").List();
			Assert.AreEqual(1, list.Count, "query many-to-one");

			if (DialectSupportsCountDistinct)
			{
				enumerable = s.CreateQuery("select count(distinct foo.TheFoo) from foo in class Foo").Enumerable();
				Assert.IsTrue(ContainsSingleObject(enumerable, (long) 2), "count"); // changed to Int64 (HQLFunction H3.2)
			}

			enumerable = s.CreateQuery("select count(foo.TheFoo.Boolean) from foo in class Foo").Enumerable();
			Assert.IsTrue(ContainsSingleObject(enumerable, (long) 2), "count"); // changed to Int64 (HQLFunction H3.2)

			enumerable = s.CreateQuery("select count(*), foo.Int from foo in class Foo group by foo.Int").Enumerable();
			enumerator = enumerable.GetEnumerator();
			Assert.IsTrue(enumerator.MoveNext());
			Assert.AreEqual(3L, (long) ((object[]) enumerator.Current)[0]);
			Assert.IsFalse(enumerator.MoveNext());

			enumerable = s.CreateQuery("select sum(foo.TheFoo.Int) from foo in class Foo").Enumerable();
			Assert.IsTrue(ContainsSingleObject(enumerable, (long) 4), "sum"); // changed to Int64 (HQLFunction H3.2)

			enumerable = s.CreateQuery("select count(foo) from foo in class Foo where foo.id=?")
开发者ID:remcoros,项目名称:nhibernate,代码行数:67,代码来源:FooBarTest.cs

示例5: 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

示例6: 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

示例7: 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

示例8: CollectionsInSelect

		public void CollectionsInSelect()
		{
			ISession s = OpenSession();
			ITransaction t = s.BeginTransaction();
			Foo[] foos = new Foo[] {null, new Foo()};
			s.Save(foos[1]);
			Baz baz = new Baz();
			baz.SetDefaults();
			baz.FooArray = foos;
			s.Save(baz);
			Baz baz2 = new Baz();
			baz2.SetDefaults();
			s.Save(baz2);

			Bar bar = new Bar();
			bar.Baz = baz;
			s.Save(bar);

			IList list = s.CreateQuery("select new Result(foo.String, foo.Long, foo.Integer) from foo in class Foo").List();
			Assert.AreEqual(2, list.Count);
			Assert.IsTrue(list[0] is Result);
			Assert.IsTrue(list[1] is Result);

			list =
				s.CreateQuery(
					"select new Result( baz.Name, foo.Long, count(elements(baz.FooArray)) ) from Baz baz join baz.FooArray foo group by baz.Name, foo.Long")
					.List();
			Assert.AreEqual(1, list.Count);
			Assert.IsTrue(list[0] is Result);
			Result r = (Result) list[0];

			Assert.AreEqual(baz.Name, r.Name);
			Assert.AreEqual(1, r.Count);
			Assert.AreEqual(foos[1].Long, r.Amount);


			list =
				s.CreateQuery(
					"select new Result( baz.Name, max(foo.Long), count(foo) ) from Baz baz join baz.FooArray foo group by baz.Name").
					List();
			Assert.AreEqual(1, list.Count);
			Assert.IsTrue(list[0] is Result);
			r = (Result) list[0];
			Assert.AreEqual(baz.Name, r.Name);
			Assert.AreEqual(1, r.Count);

			s.CreateQuery("select max( elements(bar.Baz.FooArray) ) from Bar as bar").List();
			// the following test is disable for databases with no subselects... also for Interbase (not sure why) - comment from h2.0.3
			if (Dialect.SupportsSubSelects)
			{
				s.CreateQuery("select count(*) from Baz as baz where 1 in indices(baz.FooArray)").List();
				s.CreateQuery("select count(*) from Bar as bar where 'abc' in elements(bar.Baz.FooArray)").List();
				s.CreateQuery("select count(*) from Bar as bar where 1 in indices(bar.Baz.FooArray)").List();
				s.CreateQuery(
					"select count(*) from Bar as bar where '1' in (from bar.Component.Glarch.ProxyArray g where g.Name='foo')").List();
				
				// The nex query is wrong and is not present in H3.2:
				// The SQL result, from Classic parser, is the same of the previous query.
				// The AST parser has some problem to parse 'from g in bar.Component.Glarch.ProxyArray'
				// which should be parsed as 'from bar.Component.Glarch.ProxyArray g'
				//s.CreateQuery(
				//  "select count(*) from Bar as bar where '1' in (from g in bar.Component.Glarch.ProxyArray.elements where g.Name='foo')")
				//  .List();

				// TODO: figure out why this is throwing an ORA-1722 error
				// probably the conversion ProxyArray.id (to_number ensuring a not null value)
				if (!(Dialect is Oracle8iDialect))
				{
					s.CreateQuery(
						"select count(*) from Bar as bar join bar.Component.Glarch.ProxyArray as g where cast(g.id as Int32) in indices(bar.Baz.FooArray)").
						List();
					s.CreateQuery(
						"select max( elements(bar.Baz.FooArray) ) from Bar as bar join bar.Component.Glarch.ProxyArray as g where cast(g.id as Int32) in indices(bar.Baz.FooArray)")
						.List();
					s.CreateQuery(
						"select count(*) from Bar as bar left outer join bar.Component.Glarch.ProxyArray as pg where '1' in (from g in bar.Component.Glarch.ProxyArray)")
						.List();
				}
			}

			list =
				s.CreateQuery("from Baz baz left join baz.FooToGlarch join fetch baz.FooArray foo left join fetch foo.TheFoo").List();
			Assert.AreEqual(1, list.Count);
			Assert.AreEqual(2, ((object[]) list[0]).Length);

			list =
				s.CreateQuery(
					"select baz.Name from Bar bar inner join bar.Baz baz inner join baz.FooSet foo where baz.Name = bar.String").List();
			s.CreateQuery(
				"SELECT baz.Name FROM Bar AS bar INNER JOIN bar.Baz AS baz INNER JOIN baz.FooSet AS foo WHERE baz.Name = bar.String")
				.List();

			s.CreateQuery(
				"select baz.Name from Bar bar join bar.Baz baz left outer join baz.FooSet foo where baz.Name = bar.String").List();

			s.CreateQuery("select baz.Name from Bar bar join bar.Baz baz join baz.FooSet foo where baz.Name = bar.String").List();
			s.CreateQuery("SELECT baz.Name FROM Bar AS bar join bar.Baz AS baz join baz.FooSet AS foo WHERE baz.Name = bar.String").List();

			s.CreateQuery(
				"select baz.Name from Bar bar left join bar.Baz baz left join baz.FooSet foo where baz.Name = bar.String").List();
//.........这里部分代码省略.........
开发者ID:remcoros,项目名称:nhibernate,代码行数:101,代码来源:FooBarTest.cs

示例9: NewFlushing

		public void NewFlushing()
		{
			ISession s = OpenSession();
			ITransaction txn = s.BeginTransaction();
			Baz baz = new Baz();
			baz.SetDefaults();
			s.Save(baz);
			s.Flush();

			baz.StringArray[0] = "a new value";
			IEnumerator enumer = s.CreateQuery("from baz in class Baz").Enumerable().GetEnumerator(); // no flush
			Assert.IsTrue(enumer.MoveNext());
			Assert.AreSame(baz, enumer.Current);

			enumer = IsClassicParser
			         	? s.CreateQuery("select baz.StringArray.elements from baz in class Baz").Enumerable().GetEnumerator()
			         	: s.CreateQuery("select elements(baz.StringArray) from baz in class Baz").Enumerable().GetEnumerator();

			bool found = false;
			while (enumer.MoveNext())
			{
				if (enumer.Current.Equals("a new value"))
				{
					found = true;
				}
			}
			Assert.IsTrue(found);

			baz.StringArray = null;
			s.CreateQuery("from baz in class Baz").Enumerable(); // no flush

			enumer = IsClassicParser
			         	? s.CreateQuery("select baz.StringArray.elements from baz in class Baz").Enumerable().GetEnumerator()
			         	: s.CreateQuery("select elements(baz.StringArray) from baz in class Baz").Enumerable().GetEnumerator();

			Assert.IsFalse(enumer.MoveNext());

			baz.StringList.Add("1E1");
			enumer = s.CreateQuery("from foo in class Foo").Enumerable().GetEnumerator(); // no flush
			Assert.IsFalse(enumer.MoveNext());

			enumer = IsClassicParser
			         	? s.CreateQuery("select baz.StringList.elements from baz in class Baz").Enumerable().GetEnumerator()
			         	: s.CreateQuery("select elements(baz.StringList) from baz in class Baz").Enumerable().GetEnumerator();

			found = false;
			while (enumer.MoveNext())
			{
				if (enumer.Current.Equals("1E1"))
				{
					found = true;
				}
			}
			Assert.IsTrue(found);

			baz.StringList.Remove("1E1");
			if (IsClassicParser)
			{
				s.CreateQuery("select baz.StringArray.elements from baz in class Baz").Enumerable(); //no flush
			}
			else
			{
				s.CreateQuery("select elements(baz.StringArray) from baz in class Baz").Enumerable(); //no flush
			}

			enumer = IsClassicParser
			         	? s.CreateQuery("select baz.StringList.elements from baz in class Baz").Enumerable().GetEnumerator()
			         	: s.CreateQuery("select elements(baz.StringList) from baz in class Baz").Enumerable().GetEnumerator();

			found = false;
			while (enumer.MoveNext())
			{
				if (enumer.Current.Equals("1E1"))
				{
					found = true;
				}
			}
			Assert.IsFalse(found);

			IList newList = new ArrayList();
			newList.Add("value");
			baz.StringList = newList;
			
			s.CreateQuery("from foo in class Foo").Enumerable().GetEnumerator(); //no flush
			
			baz.StringList = null;

			enumer = IsClassicParser
			         	? s.CreateQuery("select baz.StringList.elements from baz in class Baz").Enumerable().GetEnumerator()
			         	: s.CreateQuery("select elements(baz.StringList) from baz in class Baz").Enumerable().GetEnumerator();

			Assert.IsFalse(enumer.MoveNext());

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

示例10: 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

示例11: 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

示例12: ReuseDeletedCollection

		public void ReuseDeletedCollection()
		{
			Baz baz, baz2;

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

				baz2 = new Baz();
				baz2.StringArray = new string[] {"x-y-z"};
				s.Save(baz2);
				s.Flush();
			}

			baz2.StringSet = baz.StringSet;
			baz2.StringArray = baz.StringArray;
			baz2.FooArray = baz.FooArray;

			using (ISession s = OpenSession())
			{
				s.Update(baz2);
				s.Flush();
			}

			using (ISession s = OpenSession())
			{
				baz2 = (Baz) s.Load(typeof(Baz), baz2.Code);
				Assert.AreEqual(3, baz2.StringArray.Length);
				Assert.AreEqual(3, baz2.StringSet.Count);
				s.Delete(baz2);
				s.Flush();
			}
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:37,代码来源:FooBarTest.cs

示例13: CollectionsInSelect

        public void CollectionsInSelect()
        {
            ISession s = OpenSession();
            ITransaction t = s.BeginTransaction();
            Foo[] foos = new Foo[] {null, new Foo()};
            s.Save(foos[1]);
            Baz baz = new Baz();
            baz.SetDefaults();
            baz.FooArray = foos;
            s.Save(baz);
            Baz baz2 = new Baz();
            baz2.SetDefaults();
            s.Save(baz2);

            Bar bar = new Bar();
            bar.Baz = baz;
            s.Save(bar);

            IList list = s.CreateQuery("select new Result(foo.String, foo.Long, foo.Integer) from foo in class Foo").List();
            Assert.AreEqual(2, list.Count);
            Assert.IsTrue(list[0] is Result);
            Assert.IsTrue(list[1] is Result);

            list =
                s.CreateQuery(
                    "select new Result( baz.Name, foo.Long, count(elements(baz.FooArray)) ) from Baz baz join baz.FooArray foo group by baz.Name, foo.Long")
                    .List();
            Assert.AreEqual(1, list.Count);
            Assert.IsTrue(list[0] is Result);
            Result r = (Result) list[0];

            Assert.AreEqual(baz.Name, r.Name);
            Assert.AreEqual(1, r.Count);
            Assert.AreEqual(foos[1].Long, r.Amount);

            list =
                s.CreateQuery(
                    "select new Result( baz.Name, max(foo.Long), count(foo) ) from Baz baz join baz.FooArray foo group by baz.Name").
                    List();
            Assert.AreEqual(1, list.Count);
            Assert.IsTrue(list[0] is Result);
            r = (Result) list[0];
            Assert.AreEqual(baz.Name, r.Name);
            Assert.AreEqual(1, r.Count);

            s.CreateQuery("select max( elements(bar.Baz.FooArray) ) from Bar as bar").List();
            // the following test is disable for databases with no subselects... also for Interbase (not sure why) - comment from h2.0.3
            if (Dialect.SupportsSubSelects)
            {
                s.CreateQuery("select count(*) from Baz as baz where 1 in indices(baz.FooArray)").List();
                s.CreateQuery("select count(*) from Bar as bar where 'abc' in elements(bar.Baz.FooArray)").List();
                s.CreateQuery("select count(*) from Bar as bar where 1 in indices(bar.Baz.FooArray)").List();
                s.CreateQuery(
                    "select count(*) from Bar as bar, bar.Component.Glarch.ProxyArray as g where g.id in indices(bar.Baz.FooArray)").
                    List();
                s.CreateQuery(
                    "select max( elements(bar.Baz.FooArray) ) from Bar as bar, bar.Component.Glarch.ProxyArray as g where g.id in indices(bar.Baz.FooArray)")
                    .List();
                s.CreateQuery(
                    "select count(*) from Bar as bar where 1 in (from bar.Component.Glarch.ProxyArray g where g.Name='foo')").List();
                s.CreateQuery(
                    "select count(*) from Bar as bar where 1 in (from g in bar.Component.Glarch.ProxyArray.elements where g.Name='foo')")
                    .List();

                // TODO: figure out why this is throwing an ORA-1722 error
                if (!(Dialect is Oracle9Dialect))
                {
                    s.CreateQuery(
                        "select count(*) from Bar as bar left outer join bar.Component.Glarch.ProxyArray as pg where 1 in (from g in bar.Component.Glarch.ProxyArray)")
                        .List();
                }
            }

            list =
                s.CreateQuery("from Baz baz left join baz.FooToGlarch join fetch baz.FooArray foo left join fetch foo.TheFoo").List();
            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(2, ((object[]) list[0]).Length);

            list =
                s.CreateQuery(
                    "select baz.Name from Bar bar inner join bar.Baz baz inner join baz.FooSet foo where baz.Name = bar.String").List();
            s.CreateQuery(
                "SELECT baz.Name FROM Bar AS bar INNER JOIN bar.Baz AS baz INNER JOIN baz.FooSet AS foo WHERE baz.Name = bar.String")
                .List();

            s.CreateQuery(
                "select baz.Name from Bar bar join bar.Baz baz left outer join baz.FooSet foo where baz.Name = bar.String").List();

            s.CreateQuery("select baz.Name from Bar bar, bar.Baz baz, baz.FooSet foo where baz.Name = bar.String").List();
            s.CreateQuery("SELECT baz.Name FROM Bar AS bar, bar.Baz AS baz, baz.FooSet AS foo WHERE baz.Name = bar.String").List();

            s.CreateQuery(
                "select baz.Name from Bar bar left join bar.Baz baz left join baz.FooSet foo where baz.Name = bar.String").List();
            s.CreateQuery("select foo.String from Bar bar left join bar.Baz.FooSet foo where bar.String = foo.String").List();

            s.CreateQuery(
                "select baz.Name from Bar bar left join bar.Baz baz left join baz.FooArray foo where baz.Name = bar.String").List();
            s.CreateQuery("select foo.String from Bar bar left join bar.Baz.FooArray foo where bar.String = foo.String").List();

            s.CreateQuery(
//.........这里部分代码省略.........
开发者ID:aistrate,项目名称:TypingPracticeTexts,代码行数:101,代码来源: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: Databinder

		public void Databinder()
		{
			BarProxy bar;
			FooProxy foo, foo2;
			Baz baz;

			using( ISession s = OpenSession() )
			{
				bar = new Bar();
				s.Save( bar );

				foo = new Foo();
				s.Save( foo );

				foo2 = new Foo();
				s.Save( foo2 );
				foo2.TheFoo = foo;

				baz = new Baz();
				s.Save( baz );
				baz.SetDefaults();
				baz.FooArray = new FooProxy[ ] {foo, foo2, bar, null};
				bar.TheFoo = foo;
				s.Flush();
			}

			using( ISession s = OpenSession() )
			{
				bar = ( BarProxy ) s.Load( typeof( Foo ), bar.Key );
				foo = ( FooProxy ) s.Load( typeof( Foo ), foo.Key );
				foo2 = ( FooProxy ) s.Load( typeof( Foo ), foo2.Key );
				baz = ( Baz ) s.Load( typeof( Baz ), baz.Code );

				IDatabinder binder = sessions.OpenDatabinder();
				binder.InitializeLazy = true;
				binder
					.Bind( foo2 )
					.Bind( baz )
					.Bind( foo )
					.Bind( bar );

				Console.WriteLine( binder.ToGenericXml() );

				binder
					.Bind( foo2 )
					.Bind( baz );

				Console.WriteLine( binder.ToXML() );

				//assertTrue( "dom", binder.toDOM()!=null );
				//assertTrue( "generic dom", binder.toGenericDOM()!=null );

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

				s.Flush();
			}
		}
开发者ID:rcarrillopadron,项目名称:nhibernate-1.0.2.0,代码行数:60,代码来源:FooBarTest.cs


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