コード例 #1
0
        public void SelectOneFieldFromRootStatement_Success()
        {
            ICriteriaQuery cq = EJBContainer.Instance.EntityManager.GetCriteriaBuilder().CreateQuery();
            IRoot          r  = cq.From("Students");

            cq.Select(r.Get("FirstName"));

            Assert.AreEqual(cq.ExpressionValue, "SELECT Students.FirstName FROM Students");
        }
コード例 #2
0
        public void SelectFieldWithAliasStatement_Success()
        {
            ICriteriaQuery cc = EJBContainer.Instance.EntityManager.GetCriteriaBuilder().CreateQuery();
            IRoot          r  = cc.From("Students");

            cc.Select(r.Get("FirstName").Alias("Name"));

            string s = cc.ToString();

            Assert.AreEqual(s, "SELECT Students.FirstName AS Name FROM Students");
        }
コード例 #3
0
        public void SelectMultipleFieldsStatement_Success()
        {
            ICriteriaQuery cc = EJBContainer.Instance.EntityManager.GetCriteriaBuilder().CreateQuery();
            IRoot          r  = cc.From("Students");

            cc.Select("FirstName", "LastName");

            string s = cc.ToString();

            Assert.AreEqual(s, "SELECT FirstName, LastName FROM Students");
        }
コード例 #4
0
        public void SelectWhere()
        {
            ICriteriaBuilder cb = EJBContainer.Instance.EntityManager.GetCriteriaBuilder();
            ICriteriaQuery   cc = cb.CreateQuery();
            IRoot            r  = cc.From("Students");

            cc.Select(r.Get("FirstName"));

            cc.Where(cb.Equal(r.Get("FirstName"), cb.Literal("'Jonas'")));

            Assert.AreEqual("SELECT Students.FirstName FROM Students WHERE Students.FirstName = 'Jonas'", cc.ExpressionValue);
        }
コード例 #5
0
        public void OrderByMultipleFieldsDescAsc()
        {
            ICriteriaBuilder cb = EJBContainer.Instance.EntityManager.GetCriteriaBuilder();
            ICriteriaQuery   cc = cb.CreateQuery();
            IRoot            r  = cc.From("Students");

            cc.Select(r.Get("FirstName"), r.Get("LastName"));

            cc.OrderBy(cb.Desc(r.Get("FirstName")), cb.Asc(r.Get("LastName")));

            Assert.AreEqual("SELECT Students.FirstName, Students.LastName FROM Students ORDER BY Students.FirstName DESC, Students.LastName ASC", cc.ExpressionValue);
        }
コード例 #6
0
        public void RightJoin()
        {
            ICriteriaBuilder cb = EJBContainer.Instance.EntityManager.GetCriteriaBuilder();
            ICriteriaQuery   cc = cb.CreateQuery();

            IRoot r = cc.From("Students");

            IJoin facultiesJoin = r.Join("Faculties", JoinType.Right, "Faculty_Id", "Id");

            cc.Select(r.Get("Firstname"), facultiesJoin.Get("Name"));

            Assert.AreEqual("SELECT Students.Firstname, Faculties.Name FROM Students RIGHT JOIN Faculties ON Students.Faculty_Id = Faculties.Id", cc.ExpressionValue);
        }