Ejemplo n.º 1
0
        public static WhereClause CreateWhereClause <TObject>(Expression <Func <TObject, bool> > expr) where TObject : DataObject
        {
            var visitor = new LinqVisitor();

            visitor.Visit(expr);
            return(visitor.GeneratedExpression);
        }
Ejemplo n.º 2
0
            protected override Expression VisitBinary(BinaryExpression node)
            {
                switch (node.NodeType)
                {
                case ExpressionType.AndAlso:
                    Visit(node.Left);
                    Visit(node.Right);
                    return(node);

                case ExpressionType.OrElse:
                    var visitor = new LinqVisitor();
                    visitor.Visit(node.Left);
                    visitor.Visit(node.Right);
                    Expressions.Add(visitor.Expressions.First().Or(visitor.Expressions.Last()));
                    return(node);
                }

                string sqlOp;

                if (!ExpressionTypeToSqlOperator.TryGetValue(node.NodeType, out sqlOp))
                {
                    return(node);
                }

                var value = GetValue(node.Right);

                if (value == null && node.NodeType == ExpressionType.Equal)
                {
                    Expressions.Add(DB.Column(GetColumnName(node.Left)).IsNull());
                }
                else if (value == null && node.NodeType == ExpressionType.NotEqual)
                {
                    Expressions.Add(DB.Column(GetColumnName(node.Left)).IsNotNull());
                }
                else
                {
                    Expressions.Add(new FilterExpression(GetColumnName(node.Left), sqlOp, value));
                }

                return(node);
            }
Ejemplo n.º 3
0
        public IDbOper <T> Where(Expression <Func <T, bool> > sl)
        {
            List <object> tp = null; var dc = Fields;

            using (var tp1 = new LinqVisitor())
            {
                tp = tp1.Visit(sl) as List <object>;
                StringBuilder sb = new StringBuilder(); string s = string.Empty;
                var           a = ps.Count;
                for (int i = 0; i < tp.Count; i += 4)
                {
                    s = db.ParStr("Par" + (a + i));// db.ParStr(tp[i].ToString());
                    sb.Append(Quote(tp[i].ToString()) + tp[i + 1].ToString() + s);
                    if (i + 4 < tp.Count)
                    {
                        sb.Append(tp[i + 3]);
                    }
                    ps.Add(db.Cp(s, tp[i + 2]));
                }
                Where(sb.ToString());
            }
            return(this);
        }