public void CommonUse()
        {
            // some times the select can be static in son place (the service of a DAO)
            Select s = new Select("f.Name, f.Description, b.Descriptoin").From("Foo f join f.Bar b");

            // Create a new where by checking some contition
            Where where = new Where();

            // check something and set a condition of where clause
            where.And("f.Name like :pName");

            // check something else and set another condition of where clause
            where.And("b.Asociated > :pAso");

            // Inject the where to the select
            s.From().SetWhere(where);

            // Create a basic order by
            OrderBy order = new OrderBy().Add("b.Asociated", true);

            // Check some condition and add an order
            order.Add("f.Name");

            // Inject the OrderBy to the select
            s.From().SetOrderBy(order);

            // And: The winner is....
            string expected =
                "select f.Name, f.Description, b.Descriptoin from Foo f join f.Bar b where ((f.Name like :pName) and (b.Asociated > :pAso)) order by b.Asociated desc, f.Name";
            Assert.AreEqual(expected, s.Clause);
        }
 public Where Clone()
 {
     Where result = new Where(negatingAll);
     result.expressions = null;
     result.expressions = new List<IQueryPart>(expressions);
     return result;
 }
Example #3
0
 public Where Where()
 {
     if (where == null)
     {
         where = new Where();
     }
     return where;
 }
        public void DirtyWhereCostruction()
        {
            // This way, to construct the where clause, can be useful if 
            // you don't know which will be the first expression
            Where w = new Where();
            w.And("f.Name like :p1").And("length(f.Name)>2").Or("f.Name like 'N%'");
            Assert.AreEqual("where ((f.Name like :p1) and (length(f.Name)>2) or (f.Name like 'N%'))", w.Clause);

            w = new Where();
            w.Or("f.Name like :p1").And("length(f.Name)>2").Or("f.Name like 'N%'");
            Assert.AreEqual("where ((f.Name like :p1) and (length(f.Name)>2) or (f.Name like 'N%'))", w.Clause);
        }
        public void ToRowCount()
        {
            Select s = new Select("f.Name, f.Description, b.Descriptoin").From("Foo f join f.Bar b");
            Where where = new Where();
            where.And("f.Name like :pName");
            where.And("b.Asociated > :pAso");
            s.From().SetWhere(where);
            OrderBy order = new OrderBy().Add("b.Asociated", true);
            order.Add("f.Name");
            s.From().SetOrderBy(order);

            DetachedDynQuery ddq = new DetachedDynQuery(s);
            DetachedQuery drc = (DetachedQuery) ddq.TransformToRowCount();
            Assert.AreEqual(
                "select count(*) from Foo f join f.Bar b where ((f.Name like :pName) and (b.Asociated > :pAso))",
                drc.Hql);
        }
Example #6
0
 public Where WhereNot()
 {
     if (where != null)
     {
         throw new NotSupportedException(
             string.Format("Can't override the 'where' clause; original 'where':{0}", where.Clause));
     }
     where = new Where(true);
     return where;
 }
Example #7
0
 public void SetWhere(Where whereClause)
 {
     if (whereClause == null)
     {
         throw new ArgumentNullException("whereClause");
     }
     where = whereClause;
 }