public void SelectMultipleFieldsMultipleRootsStatement_Success() { ICriteriaQuery cc = EJBContainer.Instance.EntityManager.GetCriteriaBuilder().CreateQuery(); IRoot r = cc.From("Students"); IRoot r2 = cc.From("Faculties"); cc.Select(r.Get("FirstName"), r2.Get("Name")); string s = cc.ToString(); Assert.AreEqual(s, "SELECT Students.FirstName, Faculties.Name FROM Students, Faculties"); }
public void Disjunction() { ICriteriaBuilder cb = EJBContainer.Instance.EntityManager.GetCriteriaBuilder(); ICriteriaQuery cq = cb.CreateQuery(); IRoot r = cq.From("Students"); IPredicate criteria = cb.Disjunction(); IParameterExpression pr = cb.Parameter(System.Data.SqlDbType.Int, "3"); criteria = cb.Or(criteria, cb.Equal(r.Get("SequenceNumber"), pr) ); pr = cb.Parameter(System.Data.SqlDbType.Int, "'Jonas'"); criteria = cb.Or(criteria, cb.Equal(r.Get("FirstName"), pr) ); pr = cb.Parameter(System.Data.SqlDbType.Int, "'Petraitis'"); criteria = cb.Or(criteria, cb.Equal(r.Get("LastName"), pr) ); Assert.AreEqual("Students.SequenceNumber = 3 OR Students.FirstName = 'Jonas' OR Students.LastName = 'Petraitis'", criteria.ExpressionValue); }
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"); }
public void NotLike_Success() { ICriteriaBuilder cb = EJBContainer.Instance.EntityManager.GetCriteriaBuilder(); ICriteriaQuery cq = cb.CreateQuery(); IRoot r = cq.From("Students"); IPredicate exp = cb.NotLike(r.Get("FirstName"), cb.Literal("'Jon%'")); Assert.AreEqual("Students.FirstName NOT LIKE 'Jon%'", exp.ExpressionValue); }
public void Between_Success() { ICriteriaBuilder cb = EJBContainer.Instance.EntityManager.GetCriteriaBuilder(); ICriteriaQuery cq = cb.CreateQuery(); IRoot r = cq.From("Students"); IPredicate exp = cb.Between(r.Get("SequenceNumber"), cb.Literal("2"), cb.Literal("3")); Assert.AreEqual("Students.SequenceNumber BETWEEN 2 AND 3", exp.ExpressionValue); }
public void EqualWithoutQuotes() { ICriteriaBuilder cb = EJBContainer.Instance.EntityManager.GetCriteriaBuilder(); ICriteriaQuery cq = cb.CreateQuery(); IRoot r = cq.From("Students"); IPredicate exp = cb.Equal(r.Get("FirstName"), r.Get("LastName")); Assert.AreEqual("Students.FirstName = Students.LastName", exp.ExpressionValue); }
public void EqualWithQuotes() { ICriteriaBuilder cb = EJBContainer.Instance.EntityManager.GetCriteriaBuilder(); ICriteriaQuery cq = cb.CreateQuery(); IRoot r = cq.From("Students"); IPredicate exp = cb.Equal(cb.Literal("'FirstName'"), cb.Literal("'Jonas'")); Assert.AreEqual("'FirstName' = 'Jonas'", exp.ExpressionValue); }
public void IsNotNull() { ICriteriaBuilder cb = EJBContainer.Instance.EntityManager.GetCriteriaBuilder(); ICriteriaQuery cq = cb.CreateQuery(); IRoot r = cq.From("Students"); IPredicate exp = cb.IsNotNull(r.Get("LastName")); Assert.AreEqual("Students.LastName IS NOT NULL", exp.ExpressionValue); }
public void DistinctSelectMultipleFieldsStatement_Success() { ICriteriaQuery cc = EJBContainer.Instance.EntityManager.GetCriteriaBuilder().CreateQuery(); IRoot r = cc.From("Students"); cc.Select("FirstName", "LastName").Distinct(true); string s = cc.ToString(); Assert.AreEqual(s, "SELECT DISTINCT FirstName, LastName FROM Students"); }
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"); }
public void SelectAllFieldsStatement_Success() { ICriteriaQuery cc = EJBContainer.Instance.EntityManager.GetCriteriaBuilder().CreateQuery(); IRoot r = cc.From("Students"); cc.Select("*"); string s = cc.ToString(); Assert.AreEqual(s, "SELECT * FROM Students"); }
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); }
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); }
public void ParameterExpressoin_IntType() { ICriteriaBuilder cb = EJBContainer.Instance.EntityManager.GetCriteriaBuilder(); ICriteriaQuery cq = cb.CreateQuery(); IRoot r = cq.From("Students"); IParameterExpression pr = cb.Parameter(System.Data.SqlDbType.Int, "3"); IPredicate exp = cb.Equal(r.Get("SequenceNumber"), pr); Assert.AreEqual("Students.SequenceNumber = 3", exp.ExpressionValue); }
public void ParameterExpressoin_StringType() { ICriteriaBuilder cb = EJBContainer.Instance.EntityManager.GetCriteriaBuilder(); ICriteriaQuery cq = cb.CreateQuery(); IRoot r = cq.From("Students"); IParameterExpression pr = cb.Parameter(System.Data.SqlDbType.VarChar, "Jonas"); IPredicate exp = cb.Equal(r.Get("FirstName"), pr); Assert.AreEqual("Students.FirstName = 'Jonas'", exp.ExpressionValue); }
public void Not() { ICriteriaBuilder cb = EJBContainer.Instance.EntityManager.GetCriteriaBuilder(); ICriteriaQuery cq = cb.CreateQuery(); IRoot r = cq.From("Students"); IPredicate exp = cb.Equal(r.Get("SequenceNumber"), cb.Literal("2")); IPredicate pred = cb.Not(exp); Assert.AreEqual("NOT (Students.SequenceNumber = 2)", pred.ExpressionValue); }
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); }
public void Or() { ICriteriaBuilder cb = EJBContainer.Instance.EntityManager.GetCriteriaBuilder(); ICriteriaQuery cc = cb.CreateQuery(); IRoot r = cc.From("Students"); IPredicate left = cb.Equal(r.Get("Name"), cb.Literal("'Jonas'")); IPredicate right = cb.Equal(r.Get("Faculty_Id"), cb.Literal("3")); IExpression expr = cb.Or(left, right); Assert.AreEqual("Students.Name = 'Jonas' OR Students.Faculty_Id = 3", expr.ExpressionValue); }