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 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); }