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


C# Criteria.Course类代码示例

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


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

示例1: CourseMeetingId

		public CourseMeetingId(Course course, string day, int period, string location)
		{
			this.courseCode = course.CourseCode;
			this.day = day;
			this.period = period;
			this.location = location;
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:7,代码来源:CourseMeetingId.cs

示例2: EscapeCharacter

		public void EscapeCharacter()
		{
			Course c1 = new Course();
			c1.CourseCode = "course-1";
			c1.Description = "%1";
			Course c2 = new Course();
			c2.CourseCode = "course-2";
			c2.Description = "%2";
			Course c3 = new Course();
			c3.CourseCode = "course-3";
			c3.Description = "control";

			using (ISession session = OpenSession())
			using (ITransaction t = session.BeginTransaction())
			{
				session.Save(c1);
				session.Save(c2);
				session.Save(c3);
				t.Commit();
			}

			using (ISession session = OpenSession())
			{
				// finds all courses which have a description equal to '%1'
				Course example = new Course();
				example.Description = "&%1";
				IList result =
					session.CreateCriteria(typeof(Course)).Add(
						Example.Create(example).IgnoreCase().EnableLike().SetEscapeCharacter('&')).List();
				Assert.AreEqual(1, result.Count);
			}

			using (ISession session = OpenSession())
			{
				// finds all courses which contain '%' as the first char in the description
				Course example = new Course();
				example.Description = "&%%";
				IList result =
					session.CreateCriteria(typeof(Course)).Add(
						Example.Create(example).IgnoreCase().EnableLike().SetEscapeCharacter('&')).List();
				Assert.AreEqual(2, result.Count);
			}

			using (ISession session = OpenSession())
			using (ITransaction t = session.BeginTransaction())
			{
				session.Delete(c1);
				session.Delete(c2);
				session.Delete(c3);
				t.Commit();
			}
		}
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:52,代码来源:CriteriaQueryTest.cs

示例3: IgnoreCase

		public void IgnoreCase()
		{
			//SqlServer collation set to Latin1_General_BIN
			//when database created to validate this test
			Course c1 = new Course();
			c1.CourseCode = "course-1";
			c1.Description = "Advanced NHibernate";
			Course c2 = new Course();
			c2.CourseCode = "course-2";
			c2.Description = "advanced csharp";
			Course c3 = new Course();
			c3.CourseCode = "course-3";
			c3.Description = "advanced UnitTesting";

			using (ISession session = OpenSession())
			using (ITransaction t = session.BeginTransaction())
			{
				session.Save(c1);
				session.Save(c2);
				session.Save(c3);
				t.Commit();
			}

			// this particular selection is commented out if collation is not Latin1_General_BIN
			//using (ISession session = OpenSession())
			//{
			//    // order the courses in binary order - assumes collation Latin1_General_BIN
			//    IList result =
			//        session.CreateCriteria(typeof(Course)).AddOrder(Order.Asc("Description")).List();
			//    Assert.AreEqual(3, result.Count);
			//    Course firstResult = (Course)result[0];
			//    Assert.IsTrue(firstResult.Description.Contains("Advanced NHibernate"), "Description should have 'Advanced NHibernate', but has " + firstResult.Description);
			//}

			using (ISession session = OpenSession())
			{
				// order the courses after all descriptions have been converted to lower case
				IList result =
					session.CreateCriteria(typeof (Course)).AddOrder(Order.Asc("Description").IgnoreCase()).List();
				Assert.AreEqual(3, result.Count);
				Course firstResult = (Course) result[0];
				Assert.IsTrue(firstResult.Description.Contains("advanced csharp"), "Description should have 'advanced csharp', but has " + firstResult.Description);
			}

			using (ISession session = OpenSession())
			using (ITransaction t = session.BeginTransaction())
			{
				session.Delete(c1);
				session.Delete(c2);
				session.Delete(c3);
				t.Commit();
			}
		}
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:53,代码来源:CriteriaQueryTest.cs

示例4: AliasJoinCriterion

		public void AliasJoinCriterion()
		{
			using (ISession session = this.OpenSession())
			{
				using (ITransaction t = session.BeginTransaction())
				{
					Course courseA = new Course();
					courseA.CourseCode = "HIB-A";
					courseA.Description = "Hibernate Training A";
					session.Persist(courseA);
					
					Course courseB = new Course();
					courseB.CourseCode = "HIB-B";
					courseB.Description = "Hibernate Training B";
					session.Persist(courseB);

					Student gavin = new Student();
					gavin.Name = "Gavin King";
					gavin.StudentNumber = 232;
					gavin.PreferredCourse = courseA;
					session.Persist(gavin);

					Student leonardo = new Student();
					leonardo.Name = "Leonardo Quijano";
					leonardo.StudentNumber = 233;
					leonardo.PreferredCourse = courseB;
					session.Persist(leonardo);

					Student johnDoe = new Student();
					johnDoe.Name = "John Doe";
					johnDoe.StudentNumber = 235;
					johnDoe.PreferredCourse = null;
					session.Persist(johnDoe);

					// test == on one value exists
					IList<string> result = session.CreateCriteria<Student>()
						.CreateAlias("PreferredCourse", "pc", JoinType.LeftOuterJoin,
							Restrictions.Eq("pc.CourseCode", "HIB-A"))
						.SetProjection(Property.ForName("pc.CourseCode"))
						.AddOrder(Order.Asc("pc.CourseCode"))
						.List<string>();
					
					// can't be sure of NULL comparison ordering aside from they should
					// either come first or last
					if (result[0] == null)
					{
						Assert.IsNull(result[1]);
						Assert.AreEqual("HIB-A", result[2]);
					}
					else
					{
						Assert.IsNull(result[2]);
						Assert.IsNull(result[1]);
						Assert.AreEqual("HIB-A", result[0]);
					}

					// test == on non existent value
					result = session.CreateCriteria<Student>()
						.CreateAlias("PreferredCourse", "pc", JoinType.LeftOuterJoin,
							Restrictions.Eq("pc.CourseCode", "HIB-R"))
						.SetProjection(Property.ForName("pc.CourseCode"))
						.AddOrder(Order.Asc("pc.CourseCode"))
						.List<string>();

					Assert.AreEqual(3, result.Count);
					Assert.IsNull(result[2]);
					Assert.IsNull(result[1]);
					Assert.IsNull(result[0]);

					// test != on one existing value
					result = session.CreateCriteria<Student>()
						.CreateAlias("PreferredCourse", "pc", JoinType.LeftOuterJoin,
							Restrictions.Not(Restrictions.Eq("pc.CourseCode", "HIB-A")))
						.SetProjection(Property.ForName("pc.CourseCode"))
						.AddOrder(Order.Asc("pc.CourseCode"))
						.List<string>();

					Assert.AreEqual(3, result.Count);

					// can't be sure of NULL comparison ordering aside from they should
					// either come first or last
					if (result[0] == null)
					{
						Assert.IsNull(result[1]);
						Assert.AreEqual("HIB-B", result[2]);
					}
					else
					{
						Assert.AreEqual("HIB-B", result[0]);
						Assert.IsNull(result[1]);
						Assert.IsNull(result[2]);
					}

					// test != on one existing value (using clone)
					var criteria = session.CreateCriteria<Student>()
						.CreateAlias("PreferredCourse", "pc", JoinType.LeftOuterJoin,
						             Restrictions.Not(Restrictions.Eq("pc.CourseCode", "HIB-A")))
						.SetProjection(Property.ForName("pc.CourseCode"))
						.AddOrder(Order.Asc("pc.CourseCode"));
					var clonedCriteria = CriteriaTransformer.Clone(criteria);
//.........这里部分代码省略.........
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:101,代码来源:CriteriaQueryTest.cs

示例5: OrderProjectionAliasedTest

		public void OrderProjectionAliasedTest()
		{
			using (ISession session = OpenSession())
			using (ITransaction t = session.BeginTransaction())
			{

				Course courseA = new Course();
				courseA.CourseCode = "HIB-A";
				courseA.Description = "Hibernate Training A";
				session.Save(courseA);
			
				Student gavin = new Student();
				gavin.Name = "Gavin King";
				gavin.StudentNumber = 232;
				gavin.PreferredCourse = courseA;
				session.Save(gavin);
			
				Student leonardo = new Student();
				leonardo.Name = "Leonardo Quijano";
				leonardo.StudentNumber = 233;
				leonardo.PreferredCourse = courseA;
				session.Save(leonardo);
			
				Student johnDoe = new Student();
				johnDoe.Name = "John Doe";
				johnDoe.StudentNumber = 235;
				johnDoe.PreferredCourse = null;
				session.Save(johnDoe);
			
				IProjection conditional =
					Projections.Conditional(
						Restrictions.Eq("Name", "Gavin King"),
						Projections.Constant("Name"),
						Projections.Constant("AnotherName"));

				ICriteria criteria = session.CreateCriteria(typeof(Student));
				criteria.SetMaxResults(1);
				criteria.SetFirstResult(1);
				IList result = criteria.SetProjection(Projections.Alias(conditional, "CheckName"))
					.AddOrder(Order.Asc("CheckName"))
					.List();
	
				session.Delete(gavin);
				session.Delete(leonardo);
				session.Delete(johnDoe);
				session.Delete(courseA);

				t.Commit();
			}
		}
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:50,代码来源:CriteriaQueryTest.cs

示例6: SubselectWithComponent

		public void SubselectWithComponent()
		{
			Course course = null;
			Student gavin = null;
			DetachedCriteria dc = null;
			CityState odessaWa = null;
			Enrolment enrolment2 = null;
			
			using (ISession session = OpenSession())
			using (ITransaction t = session.BeginTransaction())
			{
				course = new Course();
				course.CourseCode = "HIB";
				course.Description = "Hibernate Training";
				session.Save(course);
				
				odessaWa = new CityState("Odessa", "WA");
	
				gavin = new Student();
				gavin.Name = "Gavin King";
				gavin.StudentNumber = 232;
				gavin.CityState = odessaWa;
				session.Save(gavin);
	
				enrolment2 = new Enrolment();
				enrolment2.Course = course;
				enrolment2.CourseCode = course.CourseCode;
				enrolment2.Semester = 3;
				enrolment2.Year = 1998;
				enrolment2.Student = gavin;
				enrolment2.StudentNumber = gavin.StudentNumber;
				gavin.Enrolments.Add(enrolment2);
				
				session.Persist(enrolment2);
	
				dc = DetachedCriteria.For<Student>()
					.Add(Property.ForName("CityState").Eq(odessaWa))
					.SetProjection(Property.ForName("CityState"));
		
				session.CreateCriteria<Student>()
					.Add(Subqueries.Exists(dc))
					.List();
				
				t.Commit();
			}

			if (TestDialect.SupportsOperatorAll)
			{
				using (ISession session = OpenSession())
				using (ITransaction t = session.BeginTransaction())
				{
					try
					{
						session.CreateCriteria<Student>()
							.Add(Subqueries.PropertyEqAll("CityState", dc))
							.List();

						Assert.Fail("should have failed because cannot compare subquery results with multiple columns");
					}
					catch (QueryException)
					{
						// expected
					}
					t.Rollback();
				}
			}

			if (TestDialect.SupportsOperatorAll)
			{
				using (ISession session = OpenSession())
				using (ITransaction t = session.BeginTransaction())
				{
					try
					{
						session.CreateCriteria<Student>()
							.Add(Property.ForName("CityState").EqAll(dc))
							.List();

						Assert.Fail("should have failed because cannot compare subquery results with multiple columns");
					}
					catch (QueryException)
					{
						// expected
					}
					finally
					{
						t.Rollback();
					}
				}
			}

			using (ISession session = OpenSession())
			using (ITransaction t = session.BeginTransaction())
			{
				try
				{
					session.CreateCriteria<Student>()
						.Add(Subqueries.In(odessaWa, dc))
						.List();
					
//.........这里部分代码省略.........
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:101,代码来源:CriteriaQueryTest.cs

示例7: ProjectionsUsingProperty

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

			Course course = new Course();
			course.CourseCode = "HIB";
			course.Description = "Hibernate Training";
			course.CourseMeetings.Add(new CourseMeeting(course, "Monday", 1, "1313 Mockingbird Lane"));
			s.Save(course);

			Student gavin = new Student();
			gavin.Name = "Gavin King";
			gavin.StudentNumber = 667;
			CityState odessaWa = new CityState("Odessa", "WA");
			gavin.CityState = odessaWa;
			gavin.PreferredCourse = course;
			s.Save(gavin);

			Student xam = new Student();
			xam.Name = "Max Rydahl Andersen";
			xam.StudentNumber = 101;
			s.Save(xam);

			Enrolment enrolment = new Enrolment();
			enrolment.Course = course;
			enrolment.CourseCode = course.CourseCode;
			enrolment.Semester = 1;
			enrolment.Year = 1999;
			enrolment.Student = xam;
			enrolment.StudentNumber = xam.StudentNumber;
			xam.Enrolments.Add(enrolment);
			s.Save(enrolment);

			enrolment = new Enrolment();
			enrolment.Course = course;
			enrolment.CourseCode = course.CourseCode;
			enrolment.Semester = 3;
			enrolment.Year = 1998;
			enrolment.Student = gavin;
			enrolment.StudentNumber = gavin.StudentNumber;
			gavin.Enrolments.Add(enrolment);
			s.Save(enrolment);
			s.Flush();

			// Subtest #1
			IList resultList = s.CreateCriteria<Enrolment>()
				.SetProjection(Projections.ProjectionList()
					.Add(Property.ForName("Student"), "student")
					.Add(Property.ForName("Course"), "course")
					.Add(Property.ForName("Semester"), "semester")
					.Add(Property.ForName("Year"), "year")
				).List();

			Assert.That(resultList.Count, Is.EqualTo(2));
			
			foreach (object[] objects in resultList)
			{
				Assert.That(objects.Length, Is.EqualTo(4));
				Assert.That(objects[0], Is.InstanceOf<Student>());
				Assert.That(objects[1], Is.InstanceOf<Course>());
				Assert.That(objects[2], Is.InstanceOf<short>());
				Assert.That(objects[3], Is.InstanceOf<short>());
			}

			// Subtest #2
			resultList = s.CreateCriteria<Student>()
				.SetProjection(Projections.ProjectionList()
					.Add(Projections.Id().As("StudentNumber"))
					.Add(Property.ForName("Name"), "name")
					.Add(Property.ForName("CityState"), "cityState")
					.Add(Property.ForName("PreferredCourse"), "preferredCourse")
				).List();
			
			Assert.That(resultList.Count, Is.EqualTo(2));
			
			foreach(object[] objects in resultList)
			{
				Assert.That(objects.Length, Is.EqualTo(4));
				Assert.That(objects[0], Is.InstanceOf<long>());
				Assert.That(objects[1], Is.InstanceOf<string>());
				
				if ("Gavin King".Equals(objects[1]))
				{
					Assert.That(objects[2], Is.InstanceOf<CityState>());
					Assert.That(objects[3], Is.InstanceOf<Course>());
				}
				else
				{
					Assert.That(objects[2], Is.Null);
					Assert.That(objects[3], Is.Null);
				}
			}
			
			// Subtest #3
			resultList = s.CreateCriteria<Student>()
				.Add(Restrictions.Eq("Name", "Gavin King"))
				.SetProjection(Projections.ProjectionList()
					.Add(Projections.Id().As("StudentNumber"))
					.Add(Property.ForName("Name"), "name")
//.........这里部分代码省略.........
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:101,代码来源:CriteriaQueryTest.cs

示例8: ProjectionsTest

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

			Course course = new Course();
			course.CourseCode = "HIB";
			course.Description = "Hibernate Training";
			s.Save(course);

			Student gavin = new Student();
			gavin.Name = "Gavin King";
			gavin.StudentNumber = 667;
			s.Save(gavin);

			Student xam = new Student();
			xam.Name = "Max Rydahl Andersen";
			xam.StudentNumber = 101;
			s.Save(xam);

			Enrolment enrolment = new Enrolment();
			enrolment.Course = course;
			enrolment.CourseCode = course.CourseCode;
			enrolment.Semester = 1;
			enrolment.Year = 1999;
			enrolment.Student = xam;
			enrolment.StudentNumber = xam.StudentNumber;
			xam.Enrolments.Add(enrolment);
			s.Save(enrolment);

			enrolment = new Enrolment();
			enrolment.Course = course;
			enrolment.CourseCode = course.CourseCode;
			enrolment.Semester = 3;
			enrolment.Year = 1998;
			enrolment.Student = gavin;
			enrolment.StudentNumber = gavin.StudentNumber;
			gavin.Enrolments.Add(enrolment);
			s.Save(enrolment);

			//s.flush();

			int count = (int)s.CreateCriteria(typeof(Enrolment))
								.SetProjection(Projections.Count("StudentNumber").SetDistinct())
								.UniqueResult();
			Assert.AreEqual(2, count);

			object obj = s.CreateCriteria(typeof(Enrolment))
				.SetProjection(Projections.ProjectionList()
								.Add(Projections.Count("StudentNumber"))
								.Add(Projections.Max("StudentNumber"))
								.Add(Projections.Min("StudentNumber"))
								.Add(Projections.Avg("StudentNumber"))
				)
				.UniqueResult();
			object[] result = (object[])obj;

			Assert.AreEqual(2, result[0]);
			Assert.AreEqual(667L, result[1]);
			Assert.AreEqual(101L, result[2]);
			Assert.AreEqual(384.0D, (Double)result[3], 0.01D);


			IList resultWithMaps = s.CreateCriteria(typeof(Enrolment))
				.SetProjection(Projections.Distinct(Projections.ProjectionList()
														.Add(Projections.Property("StudentNumber"), "stNumber")
														.Add(Projections.Property("CourseCode"), "cCode"))
				)
				.Add(Expression.Gt("StudentNumber", 665L))
				.Add(Expression.Lt("StudentNumber", 668L))
				.AddOrder(Order.Asc("stNumber"))
				.SetResultTransformer(CriteriaSpecification.AliasToEntityMap)
				.List();

			Assert.AreEqual(1, resultWithMaps.Count);
			IDictionary m1 = (IDictionary)resultWithMaps[0];

			Assert.AreEqual(667L, m1["stNumber"]);
			Assert.AreEqual(course.CourseCode, m1["cCode"]);

			resultWithMaps = s.CreateCriteria(typeof(Enrolment))
				.SetProjection(Projections.Property("StudentNumber").As("stNumber"))
				.AddOrder(Order.Desc("stNumber"))
				.SetResultTransformer(CriteriaSpecification.AliasToEntityMap)
				.List();

			Assert.AreEqual(2, resultWithMaps.Count);
			IDictionary m0 = (IDictionary)resultWithMaps[0];
			m1 = (IDictionary)resultWithMaps[1];

			Assert.AreEqual(101L, m1["stNumber"]);
			Assert.AreEqual(667L, m0["stNumber"]);


			IList resultWithAliasedBean = s.CreateCriteria(typeof(Enrolment))
				.CreateAlias("Student", "st")
				.CreateAlias("Course", "co")
				.SetProjection(Projections.ProjectionList()
								.Add(Projections.Property("st.Name"), "studentName")
								.Add(Projections.Property("co.Description"), "courseDescription")
//.........这里部分代码省略.........
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:101,代码来源:CriteriaQueryTest.cs

示例9: ProjectedCompositeIdWithAlias

		public void ProjectedCompositeIdWithAlias()
		{
			using (ISession s = OpenSession())
			using (ITransaction t = s.BeginTransaction())
			{
				Course course = new Course();
				course.CourseCode = "HIB";
				course.Description = "Hibernate Training";
				course.CourseMeetings.Add(new CourseMeeting(course, "Monday", 1, "1313 Mockingbird Lane"));
				s.Save(course);
				s.Flush();
		
				IList data = (IList)s.CreateCriteria<CourseMeeting>()
					.SetProjection(Projections.Id().As("id"))
					.List();

				t.Rollback();
			}
		}
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:19,代码来源:CriteriaQueryTest.cs

示例10: ProjectedListIncludesEmbeddedCompositeId

		public void ProjectedListIncludesEmbeddedCompositeId()
		{
			using (ISession s = OpenSession())
			using (ITransaction t = s.BeginTransaction())
			{
				Course course = new Course();
				course.CourseCode = "HIB";
				course.Description = "Hibernate Training";
				s.Save(course);
				
				Student gavin = new Student();
				gavin.Name = "Gavin King";
				gavin.StudentNumber = 667;
				s.Save(gavin);
				
				Student xam = new Student();
				xam.Name = "Max Rydahl Andersen";
				xam.StudentNumber = 101;
				s.Save(xam);
	
				Enrolment enrolment = new Enrolment();
				enrolment.Course = course;
				enrolment.CourseCode = course.CourseCode;
				enrolment.Semester = 1;
				enrolment.Year = 1999;
				enrolment.Student = xam;
				enrolment.StudentNumber = xam.StudentNumber;
				gavin.Enrolments.Add(enrolment);
				s.Save(enrolment);
				
				enrolment = new Enrolment();
				enrolment.Course = course;
				enrolment.CourseCode = course.CourseCode;
				enrolment.Semester = 3;
				enrolment.Year = 1998;
				enrolment.Student = gavin;
				enrolment.StudentNumber = gavin.StudentNumber;
				gavin.Enrolments.Add(enrolment);
				s.Save(enrolment);
	
				s.Flush();
				
				IList data = (IList)s.CreateCriteria<Enrolment>()
					.SetProjection(Projections.ProjectionList()
						.Add(Projections.Property("Semester"))
						.Add(Projections.Property("Year"))
						.Add(Projections.Id()))
				.List();
				
				t.Rollback();
			}
		}
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:52,代码来源:CriteriaQueryTest.cs

示例11: CloningProjectionsUsingProperty

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

			Course course = new Course();
			course.CourseCode = "HIB";
			course.Description = "Hibernate Training";
			s.Save(course);

			Student gavin = new Student();
			gavin.Name = "Gavin King";
			gavin.StudentNumber = 667;
			s.Save(gavin);

			Student xam = new Student();
			xam.Name = "Max Rydahl Andersen";
			xam.StudentNumber = 101;
			s.Save(xam);

			Enrolment enrolment = new Enrolment();
			enrolment.Course = course;
			enrolment.CourseCode = course.CourseCode;
			enrolment.Semester = 1;
			enrolment.Year = 1999;
			enrolment.Student = xam;
			enrolment.StudentNumber = xam.StudentNumber;
			xam.Enrolments.Add(enrolment);
			s.Save(enrolment);

			enrolment = new Enrolment();
			enrolment.Course = course;
			enrolment.CourseCode = course.CourseCode;
			enrolment.Semester = 3;
			enrolment.Year = 1998;
			enrolment.Student = gavin;
			enrolment.StudentNumber = gavin.StudentNumber;
			gavin.Enrolments.Add(enrolment);
			s.Save(enrolment);
			s.Flush();

			int count = (int)CriteriaTransformer.Clone(s.CreateCriteria(typeof(Enrolment))
															.SetProjection(Property.ForName("StudentNumber").Count().SetDistinct())
								)
								.UniqueResult();
			Assert.AreEqual(2, count);

			object obj = CriteriaTransformer.Clone(s.CreateCriteria(typeof(Enrolment))
													.SetProjection(Projections.ProjectionList()
																	.Add(Property.ForName("StudentNumber").Count())
																	.Add(Property.ForName("StudentNumber").Max())
																	.Add(Property.ForName("StudentNumber").Min())
																	.Add(Property.ForName("StudentNumber").Avg())
													)
				)
				.UniqueResult();
			object[] result = (object[])obj;

			Assert.AreEqual(2, result[0]);
			Assert.AreEqual(667L, result[1]);
			Assert.AreEqual(101L, result[2]);
			Assert.AreEqual(384.0D, (double)result[3], 0.01D);


			CriteriaTransformer.Clone(
				s.CreateCriteria(typeof(Enrolment))
					.Add(Property.ForName("StudentNumber").Gt(665L))
					.Add(Property.ForName("StudentNumber").Lt(668L))
					.Add(Property.ForName("CourseCode").Like("HIB", MatchMode.Start))
					.Add(Property.ForName("Year").Eq((short)1999))
					.AddOrder(Property.ForName("StudentNumber").Asc())
				)
				.UniqueResult();

			ICriteria clonedCriteriaProjection = CriteriaTransformer.Clone(s.CreateCriteria(typeof(Enrolment))
																			.SetProjection(Projections.ProjectionList()
																							.Add(Property.ForName("StudentNumber").As("stNumber"))
																							.Add(Property.ForName("CourseCode").As("cCode"))
																			)
																			.Add(Property.ForName("StudentNumber").Gt(665L))
																			.Add(Property.ForName("StudentNumber").Lt(668L))
																			.AddOrder(Property.ForName("StudentNumber").Asc())
																			.SetResultTransformer(CriteriaSpecification.AliasToEntityMap)
				);
			IList resultWithMaps = clonedCriteriaProjection
				.List();

			Assert.AreEqual(1, resultWithMaps.Count);
			IDictionary m1 = (IDictionary)resultWithMaps[0];

			Assert.AreEqual(667L, m1["stNumber"]);
			Assert.AreEqual(course.CourseCode, m1["cCode"]);

			resultWithMaps = CriteriaTransformer.Clone(s.CreateCriteria(typeof(Enrolment))
														.SetProjection(Property.ForName("StudentNumber").As("stNumber"))
														.AddOrder(Order.Desc("stNumber"))
														.SetResultTransformer(CriteriaSpecification.AliasToEntityMap)
				)
				.List();

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

示例12: GroupByComponent

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

			Course course = new Course();
			course.CourseCode = "HIB";
			course.Description = "Hibernate Training";
			s.Save(course);

			Student gavin = new Student();
			gavin.Name = "Gavin King";
			gavin.StudentNumber = 667;
			gavin.CityState = new CityState("Odessa", "WA");;
			s.Save(gavin);

			Student xam = new Student();
			xam.Name = "Max Rydahl Andersen";
			xam.StudentNumber = 101;
			xam.PreferredCourse = course;
			xam.CityState = new CityState("Odessa", "WA");;
			s.Save(xam);

			Enrolment enrolment = new Enrolment();
			enrolment.Course = course;
			enrolment.CourseCode = course.CourseCode;
			enrolment.Semester = 1;
			enrolment.Year = 1999;
			enrolment.Student = xam;
			enrolment.StudentNumber = xam.StudentNumber;
			xam.Enrolments.Add(enrolment);
			s.Save(enrolment);

			enrolment = new Enrolment();
			enrolment.Course = course;
			enrolment.CourseCode = course.CourseCode;
			enrolment.Semester = 3;
			enrolment.Year = 1998;
			enrolment.Student = gavin;
			enrolment.StudentNumber = gavin.StudentNumber;
			gavin.Enrolments.Add(enrolment);
			s.Save(enrolment);
			s.Flush();
	
			object result = s.CreateCriteria<Student>()
				.SetProjection(Projections.GroupProperty("CityState"))
				.UniqueResult();
			
			Assert.That(result, Is.InstanceOf<CityState>());
			Assert.That(((CityState)result).City, Is.EqualTo("Odessa"));
			Assert.That(((CityState)result).State, Is.EqualTo("WA"));
	
			result = s.CreateCriteria<Student>("st")
				.SetProjection(Projections.GroupProperty("st.CityState"))
				.UniqueResult();

			Assert.That(result, Is.InstanceOf<CityState>());
			Assert.That(((CityState)result).City, Is.EqualTo("Odessa"));
			Assert.That(((CityState)result).State, Is.EqualTo("WA"));
	
			result = s.CreateCriteria<Student>("st")
				.SetProjection(Projections.GroupProperty("st.CityState"))
				.AddOrder(Order.Asc("CityState"))
				.UniqueResult();
			
			Assert.That(result, Is.InstanceOf<CityState>());
			Assert.That(((CityState)result).City, Is.EqualTo("Odessa"));
			Assert.That(((CityState)result).State, Is.EqualTo("WA"));
	
			result = s.CreateCriteria<Student>("st")
				.SetProjection(Projections.GroupProperty("st.CityState").As("cityState"))
				.AddOrder(Order.Asc("cityState"))
				.UniqueResult();
			
			Assert.That(result, Is.InstanceOf<CityState>());
			Assert.That(((CityState)result).City, Is.EqualTo("Odessa"));
			Assert.That(((CityState)result).State, Is.EqualTo("WA"));
	
			result = s.CreateCriteria<Student>("st")
				.SetProjection(Projections.GroupProperty("st.CityState").As("cityState"))
				.AddOrder(Order.Asc("cityState"))
				.UniqueResult();
			
			Assert.That(result, Is.InstanceOf<CityState>());
			Assert.That(((CityState)result).City, Is.EqualTo("Odessa"));
			Assert.That(((CityState)result).State, Is.EqualTo("WA"));
	
			result = s.CreateCriteria<Student>("st")
				.SetProjection(Projections.GroupProperty("st.CityState").As("cityState"))
				.Add(Restrictions.Eq("st.CityState", new CityState("Odessa", "WA")))
				.AddOrder(Order.Asc("cityState"))
				.UniqueResult();
			
			Assert.That(result, Is.InstanceOf<CityState>());
			Assert.That(((CityState)result).City, Is.EqualTo("Odessa"));
			Assert.That(((CityState)result).State, Is.EqualTo("WA"));
	
			IList list = s.CreateCriteria<Enrolment>()
				.CreateAlias("Student", "st")
				.CreateAlias("Course", "co")
//.........这里部分代码省略.........
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:101,代码来源:CriteriaQueryTest.cs

示例13: DistinctProjectionsOfComponents

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

			Course course = new Course();
			course.CourseCode = "HIB";
			course.Description = "Hibernate Training";
			s.Save(course);

			Student gavin = new Student();
			gavin.Name = "Gavin King";
			gavin.StudentNumber = 667;
			gavin.CityState = new CityState("Odessa", "WA");;
			s.Save(gavin);

			Student xam = new Student();
			xam.Name = "Max Rydahl Andersen";
			xam.StudentNumber = 101;
			xam.PreferredCourse = course;
			xam.CityState = new CityState("Odessa", "WA");;
			s.Save(xam);

			Enrolment enrolment = new Enrolment();
			enrolment.Course = course;
			enrolment.CourseCode = course.CourseCode;
			enrolment.Semester = 1;
			enrolment.Year = 1999;
			enrolment.Student = xam;
			enrolment.StudentNumber = xam.StudentNumber;
			xam.Enrolments.Add(enrolment);
			s.Save(enrolment);

			enrolment = new Enrolment();
			enrolment.Course = course;
			enrolment.CourseCode = course.CourseCode;
			enrolment.Semester = 3;
			enrolment.Year = 1998;
			enrolment.Student = gavin;
			enrolment.StudentNumber = gavin.StudentNumber;
			gavin.Enrolments.Add(enrolment);
			s.Save(enrolment);
			s.Flush();
			
			object result = s.CreateCriteria<Student>()
				.SetProjection(Projections.Distinct(Property.ForName("CityState")))
				.UniqueResult();
			
			Assert.That(result, Is.InstanceOf<CityState>());
			Assert.That(((CityState)result).City, Is.EqualTo("Odessa"));
			Assert.That(((CityState)result).State, Is.EqualTo("WA"));
	
			result = s.CreateCriteria<Student>()
				.SetProjection(Projections.Distinct(Property.ForName("CityState").As("cityState")))
				.AddOrder(Order.Asc("cityState"))
				.UniqueResult();
			
			Assert.That(result, Is.InstanceOf<CityState>());
			Assert.That(((CityState)result).City, Is.EqualTo("Odessa"));
			Assert.That(((CityState)result).State, Is.EqualTo("WA"));
	
			result = s.CreateCriteria<Student>()
				.SetProjection(Projections.Count("CityState.City"))
				.UniqueResult();
			
			Assert.That(result, Is.EqualTo(2));
	
			result = s.CreateCriteria<Student>()
				.SetProjection(Projections.CountDistinct("CityState.City"))
				.UniqueResult();
			
			Assert.That(result, Is.EqualTo(1));
			
			t.Commit();
			s.Close();

//			s = OpenSession();
//			t = s.BeginTransaction();
//			try
//			{
//				result = s.CreateCriteria<Student>()
//					.SetProjection(Projections.Count("CityState"))
//					.UniqueResult();
//				
//				if (!Dialect.SupportsTupleCounts)
//				{
//					fail( "expected SQLGrammarException" );
//				}
//				
//				Assert.That((long)result, Is.EqualTo(1L));
//			}
//			catch (NHibernate.Exceptions.SQLGrammarException ex)
//			{
//				throw ex;
//				if (!Dialect.SupportsTupleCounts)
//				{
//					// expected
//				}
//				else 
//				{
//.........这里部分代码省略.........
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:101,代码来源:CriteriaQueryTest.cs

示例14: Subselect

		public void Subselect()
		{
			ISession session = OpenSession();
			ITransaction t = session.BeginTransaction();

			Course course = new Course();
			course.CourseCode = "HIB";
			course.Description = "Hibernate Training";
			session.Save(course);

			Student gavin = new Student();
			gavin.Name = "Gavin King";
			gavin.StudentNumber = 232;
			session.Save(gavin);

			Enrolment enrolment2 = new Enrolment();
			enrolment2.Course = course;
			enrolment2.CourseCode = course.CourseCode;
			enrolment2.Semester = 3;
			enrolment2.Year = 1998;
			enrolment2.Student = gavin;
			enrolment2.StudentNumber = gavin.StudentNumber;
			gavin.Enrolments.Add(enrolment2);
			session.Save(enrolment2);

			DetachedCriteria dc = DetachedCriteria.For(typeof(Student))
				.Add(Property.ForName("StudentNumber").Eq(232L))
				.SetProjection(Property.ForName("Name"));

			if (TestDialect.SupportsOperatorAll)
			{
				session.CreateCriteria(typeof (Student))
					.Add(Subqueries.PropertyEqAll("Name", dc))
					.List();
			}

			session.CreateCriteria(typeof(Student))
				.Add(Subqueries.Exists(dc))
				.List();

			if (TestDialect.SupportsOperatorAll)
			{
				session.CreateCriteria(typeof (Student))
					.Add(Property.ForName("Name").EqAll(dc))
					.List();
			}

			session.CreateCriteria(typeof(Student))
				.Add(Subqueries.In("Gavin King", dc))
				.List();

			DetachedCriteria dc2 = DetachedCriteria.For(typeof(Student), "st")
				.Add(Property.ForName("st.StudentNumber").EqProperty("e.StudentNumber"))
				.SetProjection(Property.ForName("Name"));

			session.CreateCriteria(typeof(Enrolment), "e")
				.Add(Subqueries.Eq("Gavin King", dc2))
				.List();

			DetachedCriteria dc3 = DetachedCriteria.For(typeof(Student), "st")
				.CreateCriteria("Enrolments")
				.CreateCriteria("Course")
				.Add(Property.ForName("Description").Eq("Hibernate Training"))
				.SetProjection(Property.ForName("st.Name"));

			session.CreateCriteria(typeof(Enrolment), "e")
				.Add(Subqueries.Eq("Gavin King", dc3))
				.List();

			DetachedCriteria courseCriteria = DetachedCriteria.For(typeof(Course))
				.Add(Property.ForName("Description").Eq("Hibernate Training"))
				.SetProjection(Projections.Property("CourseCode"));

			DetachedCriteria enrolmentCriteria = DetachedCriteria.For(typeof(Enrolment))
				.Add(Property.ForName("CourseCode").Eq(courseCriteria))
				.SetProjection(Projections.Property("CourseCode"));

			DetachedCriteria studentCriteria = DetachedCriteria.For(typeof(Student))
				.Add(Subqueries.Exists(enrolmentCriteria));

			object result = studentCriteria.GetExecutableCriteria(session).UniqueResult();
			Assert.AreSame(gavin, result);

			session.Delete(enrolment2);
			session.Delete(gavin);
			session.Delete(course);
			t.Commit();
			session.Close();
		}
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:89,代码来源:CriteriaQueryTest.cs

示例15: TestSubcriteriaBeingNull

		public void TestSubcriteriaBeingNull()
		{
			ISession session = OpenSession();
			ITransaction t = session.BeginTransaction();

			Course hibernateCourse = new Course();
			hibernateCourse.CourseCode = "HIB";
			hibernateCourse.Description = "Hibernate Training";
			session.Save(hibernateCourse);

			DetachedCriteria subcriteria = DetachedCriteria.For<Enrolment>("e");
			subcriteria.Add(Expression.EqProperty("e.CourseCode", "c.CourseCode"));
			subcriteria.SetProjection(Projections.Avg("Semester"));

			DetachedCriteria criteria = DetachedCriteria.For<Course>("c");
			criteria.SetProjection(Projections.Count("id"));
			criteria.Add(Expression.Or(Subqueries.Le(5, subcriteria), Subqueries.IsNull(subcriteria)));

			object o = criteria.GetExecutableCriteria(session).UniqueResult();
			Assert.AreEqual(1, o);

			session.Delete(hibernateCourse);
			t.Commit();
			session.Close();
		}
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:25,代码来源:CriteriaQueryTest.cs


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