public void CanMinProjectionOnIdentityProjection() { using (ISession s = OpenSession()) { ISQLFunction arithmaticAddition = new VarArgsSQLFunction("(", "+", ")"); ICriteria c = s.CreateCriteria(typeof (Person)).SetProjection( Projections.Min(Projections.SqlFunction(arithmaticAddition, NHibernateUtil.GuessType(typeof (double)), Projections.Property("IQ"), Projections.Property("ShoeSize")))); IList list = c.List(); Assert.AreEqual(19, list[0]); } }
public void OrderProjectionTest() { ISQLFunction arithmaticMultiplication = new VarArgsSQLFunction("(", "*", ")"); using (ISession session = this.OpenSession()) { ICriteria criteria = session.CreateCriteria(typeof (Person), "c"); criteria.AddOrder(Order.Asc( Projections.SqlFunction(arithmaticMultiplication, NHibernateUtil.GuessType(typeof (int)), Projections.Property("IQ"), Projections.Constant(-1)))); IList<Person> results=criteria.List<Person>(); Assert.AreEqual(5, results.Count); Assert.AreEqual("Sally", results[0].Name); Assert.AreEqual("Joe", results[4].Name); } }
public void VarArgsFunction() { IList args = new ArrayList(); VarArgsSQLFunction vf = new VarArgsSQLFunction("(", " || ", ")"); Assert.AreEqual("()", vf.Render(args, factoryImpl).ToString()); args.Add("va1"); Assert.AreEqual("(va1)", vf.Render(args, factoryImpl).ToString()); args.Clear(); args.Add("va1"); args.Add("va2"); args.Add("va3"); Assert.AreEqual("(va1 || va2 || va3)", vf.Render(args, factoryImpl).ToString()); }
public void CanOrderBySqlProjectionDesc() { using (ISession s = OpenSession()) { ISQLFunction arithmaticAddition = new VarArgsSQLFunction("(", "+", ")"); ICriteria c = s.CreateCriteria(typeof (Person)).AddOrder( Order.Desc(Projections.SqlFunction(arithmaticAddition, NHibernateUtil.GuessType(typeof (double)), Projections.Property("IQ"), Projections.Property("ShoeSize")))); IList<Person> list = c.List<Person>(); for (int i = 0; i < list.Count - 1; i++) { Assert.IsTrue(list[i].IQ + list[i].ShoeSize >= list[i + 1].IQ + list[i + 1].ShoeSize); } } }