Ejemplo n.º 1
0
        public void TestCondition()
        {
            var c = Conditions.ConditionGroup().Add(
                Conditions.ConditionGroup().Add(Conditions.Eq("Name", "Phoenix")).
                Add(Conditions.BetweenAnd("Coding", 10, 30))).
                    Add(Conditions.ConditionGroup(LogicalOperator.Or).Add(Conditions.Eq("Name", "Fox")).Add(
                            Conditions.In(LogicalOperator.And, true, "Name", "2", "3")).Add(Conditions.Like("Name", "PH")));
            var hql   = c.ToHql();
            var query = sessionFactory.OpenSession().CreateQuery("From Code where " + c.ToHql());

            Console.WriteLine(query.QueryString);
            var ps = c.Parameters;
            var ns = query.NamedParameters;

            foreach (var p in ps)
            {
                Console.WriteLine(p);
            }

            Console.WriteLine("===================================");

            foreach (var n in ns)
            {
                Console.WriteLine(n);
            }
            //for (int i = 0; i < ps.Length; i ++ )
            //{
            //    var p = ps[i];
            //    if (p is IList)
            //    {
            //        query.SetParameterList(query.NamedParameters[i], p as IList);
            //    }
            //    else
            //    {
            //        query.SetParameter(query.NamedParameters[i], p);
            //    }
            //}

            //Console.WriteLine(query.List<Code>().Count);
        }
Ejemplo n.º 2
0
        public void ConditionTest()
        {
            var c = Conditions.ConditionGroup().Add(Conditions.ConditionGroup().Add(Conditions.Eq("Name", "Phoenix")).Add(Conditions.BetweenAnd("Age", 10, 30))).
                    Add(Conditions.ConditionGroup(LogicalOperator.Or).Add(Conditions.Eq("Name", "Fox")).Add(Conditions.In(LogicalOperator.And, true, "Depart.ID", 1, 2, 3, 4)));

            Console.WriteLine(c.ToHql());
            foreach (var o in c.Parameters)
            {
                Console.WriteLine(o);
            }
        }