Esempio n. 1
0
        protected override SqlPack Having(BinaryExpression expression, SqlPack sqlPack)
        {
            if (HasBeginInOwnLogic(expression, sqlPack))
            {
                sqlPack += " (";
            }


            FluentExpressionSQLProvider.Where(expression.Left, sqlPack);
            int signIndex = sqlPack.Length;

            FluentExpressionSQLProvider.Where(expression.Right, sqlPack);
            int sqlLength = sqlPack.Length;

            if (sqlLength - signIndex == 5 && sqlPack.ToString().EndsWith("null"))
            {
                OperatorParser(expression.NodeType, signIndex, sqlPack, true);
            }
            else
            {
                OperatorParser(expression.NodeType, signIndex, sqlPack);
            }

            if (HasEndInOwnLogic(expression, sqlPack))
            {
                sqlPack += ")";
            }
            return(sqlPack);
        }
Esempio n. 2
0
        private static void Contains(MethodCallExpression expression, SqlPack sqlPack)
        {
            MethodInfo method = expression.Method;

            if (method.DeclaringType == typeof(String) || method.DeclaringType == typeof(string))
            {
                if (expression.Object != null)
                {
                    FluentExpressionSQLProvider.Where(expression.Object, sqlPack);
                }
                string result = "";

                var column = expression.Arguments[0].GetValueOrColumnName(sqlPack);

                result = sqlPack.SqlDialectProvider.ConvertDbFunction(DbFunctionType.Contains, column);

                sqlPack += " LIKE ";

                sqlPack.CurrentDbFunctionResult = result;
            }
            else
            {
                var declaringType = method.DeclaringType;
                // typeof(IList).IsAssignableFrom(declaringType) || typeof(IEnumerable).IsAssignableFrom(declaringType) || (declaringType.IsGenericType && typeof(ICollection<>).MakeGenericType(declaringType.GetGenericArguments()).IsAssignableFrom(declaringType))
                if (declaringType.IsListType())
                {
                    var memberExp = expression.Object;
                    FluentExpressionSQLProvider.Where(expression.Arguments[0], sqlPack);
                    sqlPack += " IN ";
                    FluentExpressionSQLProvider.In(memberExp, sqlPack);
                }
                else if (method.IsStatic && declaringType == typeof(System.Linq.Enumerable) && expression.Arguments.Count == 2)
                {
                    FluentExpressionSQLProvider.Where(expression.Arguments[1], sqlPack);
                    sqlPack += " IN ";
                    FluentExpressionSQLProvider.In(expression.Arguments[0], sqlPack);
                }
            }



            //sqlPack += " LIKE '%' +";
            //FluentExpressionSQLProvider.Where(expression.Arguments[0], sqlPack);
            //sqlPack += " + '%'";
        }
Esempio n. 3
0
        private static void LikeLeftNot(MethodCallExpression expression, SqlPack sqlPack)
        {
            if (expression.Object != null)
            {
                FluentExpressionSQLProvider.Where(expression.Object, sqlPack);
            }
            FluentExpressionSQLProvider.Where(expression.Arguments[0], sqlPack);
            //sqlPack += " LIKE '%' +";
            //FluentExpressionSQLProvider.Where(expression.Arguments[1], sqlPack);
            string result = "";

            var column = expression.Arguments[1].GetValueOrColumnName(sqlPack);

            result = sqlPack.SqlDialectProvider.ConvertDbFunction(DbFunctionType.LikeLeft, column);

            sqlPack += " NOT LIKE ";

            sqlPack.CurrentDbFunctionResult = result;
        }
Esempio n. 4
0
        private void AppendSql(Expression exp, SqlPack sqlPack)
        {
            var expression = exp as BinaryExpression;

            FluentExpressionSQLProvider.Where(expression.Left, sqlPack);
            int signIndex = sqlPack.Length;

            FluentExpressionSQLProvider.Where(expression.Right, sqlPack);
            int sqlLength = sqlPack.Length;

            if (sqlLength - signIndex == 5 && sqlPack.ToString().EndsWith("null", StringComparison.InvariantCultureIgnoreCase))
            {
                OperatorParser(expression.NodeType, signIndex, sqlPack, true);
            }
            else
            {
                OperatorParser(expression.NodeType, signIndex, sqlPack);
            }
        }
Esempio n. 5
0
        private static void StartsWith(MethodCallExpression expression, SqlPack sqlPack)
        {
            if (expression.Object != null)
            {
                FluentExpressionSQLProvider.Where(expression.Object, sqlPack);
            }

            string result = "";

            var column = expression.Arguments[0].GetValueOrColumnName(sqlPack);

            result = sqlPack.SqlDialectProvider.ConvertDbFunction(DbFunctionType.StartsWith, column);

            sqlPack += " LIKE ";

            sqlPack.CurrentDbFunctionResult = result;


            //sqlPack += " LIKE ";

            //FluentExpressionSQLProvider.Where(expression.Arguments[0], sqlPack);
            //sqlPack += " + '%'";
        }
 protected override SqlPack Where(UnaryExpression expression, SqlPack sqlPack)
 {
     FluentExpressionSQLProvider.Where(expression.Operand, sqlPack);
     return(sqlPack);
 }
Esempio n. 7
0
 private static void InNot(MethodCallExpression expression, SqlPack sqlPack)
 {
     FluentExpressionSQLProvider.Where(expression.Arguments[0], sqlPack);
     sqlPack += " NOT IN ";
     FluentExpressionSQLProvider.In(expression.Arguments[1], sqlPack);
 }
Esempio n. 8
0
        protected override SqlPack Where(BinaryExpression expression, SqlPack sqlPack)
        {
            int signIndex = 0, sqlLength = 0;

            if (expression.NodeType == ExpressionType.AndAlso)
            {
                // true && a.ID == 1 或者 a.ID == 1 && true
                Expression         left = expression.Left, right = expression.Right;
                ConstantExpression c = right as ConstantExpression;
                // DbExpression dbExp = null;
                //a.ID == 1 && true
                if (c != null)
                {
                    if ((bool)c.Value == true)
                    {
                        // (a.ID==1)==true
                        //dbExp = new DbEqualExpression(this.Visit(exp.Left), new DbConstantExpression(true));
                        //dbExp = this.Visit(Expression.Equal(exp.Left, UtilConstants.Constant_True));
                        FluentExpressionSQLProvider.Where(expression.Left, sqlPack);

                        signIndex = sqlPack.Length;

                        sqlPack  += " " + TrueLiteral;
                        sqlLength = sqlPack.Length;

                        if (sqlLength - signIndex == 5 && sqlPack.ToString().EndsWith("null"))
                        {
                            OperatorParser(expression.NodeType, signIndex, sqlPack, true);
                        }
                        else
                        {
                            OperatorParser(expression.NodeType, signIndex, sqlPack);
                        }

                        return(sqlPack);
                    }
                    else
                    {
                        sqlPack += " " + FalseLiteral;
                        return(sqlPack);
                        //dbExp = DbEqualExpression.False;
                        // return dbExp;
                    }
                }

                c = left as ConstantExpression;
                // true && a.ID == 1
                if (c != null)
                {
                    if ((bool)c.Value == true)
                    {
                        // (a.ID==1)==true

                        sqlPack  += " " + TrueLiteral;
                        signIndex = sqlPack.Length;

                        FluentExpressionSQLProvider.Where(expression.Right, sqlPack);
                        sqlLength = sqlPack.Length;


                        if (sqlLength - signIndex == 5 && sqlPack.ToString().EndsWith("null"))
                        {
                            OperatorParser(expression.NodeType, signIndex, sqlPack, true);
                        }
                        else
                        {
                            OperatorParser(expression.NodeType, signIndex, sqlPack);
                        }

                        return(sqlPack);

                        //dbExp = this.Visit(Expression.Equal(exp.Right, UtilConstants.Constant_True));
                        //return dbExp;
                    }
                    else
                    {
                        // 直接 (1=0)

                        sqlPack += " " + FalseLiteral;
                        return(sqlPack);
                        //dbExp = DbEqualExpression.False;
                        // return dbExp;
                    }
                }
            }
            else if (expression.NodeType == ExpressionType.OrElse)
            {
                // true && a.ID == 1 或者 a.ID == 1 && true
                Expression         left = expression.Left, right = expression.Right;
                ConstantExpression c = right as ConstantExpression;
                //DbExpression dbExp = null;
                //a.ID == 1 || true
                if (c != null)
                {
                    if ((bool)c.Value == false)
                    {
                        // (a.ID==1)==true
                        FluentExpressionSQLProvider.Where(expression.Left, sqlPack);
                        signIndex = sqlPack.Length;

                        sqlPack  += " " + FalseLiteral;
                        sqlLength = sqlPack.Length;

                        if (sqlLength - signIndex == 5 && sqlPack.ToString().EndsWith("null"))
                        {
                            OperatorParser(expression.NodeType, signIndex, sqlPack, true);
                        }
                        else
                        {
                            OperatorParser(expression.NodeType, signIndex, sqlPack);
                        }

                        return(sqlPack);
                        //dbExp = this.Visit(Expression.Equal(exp.Left, UtilConstants.Constant_True));
                        //return dbExp;
                    }
                    else
                    {
                        sqlPack += " " + TrueLiteral;
                        return(sqlPack);

                        // dbExp = DbEqualExpression.True;
                        // return dbExp;
                    }
                }

                c = left as ConstantExpression;
                // true || a.ID == 1
                if (c != null)
                {
                    if ((bool)c.Value == false)
                    {
                        // (a.ID==1)==true
                        sqlPack  += " " + FalseLiteral;
                        signIndex = sqlPack.Length;

                        FluentExpressionSQLProvider.Where(expression.Right, sqlPack);
                        sqlLength = sqlPack.Length;

                        if (sqlLength - signIndex == 5 && sqlPack.ToString().EndsWith("null"))
                        {
                            OperatorParser(expression.NodeType, signIndex, sqlPack, true);
                        }
                        else
                        {
                            OperatorParser(expression.NodeType, signIndex, sqlPack);
                        }

                        return(sqlPack);

                        //dbExp = this.Visit(Expression.Equal(exp.Right, UtilConstants.Constant_True));
                        //return dbExp;
                    }
                    else
                    {
                        // 直接 (1=1)
                        sqlPack += " " + TrueLiteral;
                        return(sqlPack);
                        //dbExp = DbEqualExpression.True;
                        //return dbExp;
                    }
                }
            }



            if (HasBeginInOwnLogic(expression, sqlPack))
            {
                sqlPack += " (";
            }

            //sqlPack.WhereConditionIndex = sqlPack.WhereConditionIndex + 1;


            FluentExpressionSQLProvider.Where(expression.Left, sqlPack);
            signIndex = sqlPack.Length;

            FluentExpressionSQLProvider.Where(expression.Right, sqlPack);
            sqlLength = sqlPack.Length;

            if (sqlLength - signIndex == 5 && sqlPack.ToString().EndsWith("null"))
            {
                OperatorParser(expression.NodeType, signIndex, sqlPack, true);
            }
            else
            {
                OperatorParser(expression.NodeType, signIndex, sqlPack);
            }

            if (HasEndInOwnLogic(expression, sqlPack))
            {
                sqlPack += ")";
            }
            return(sqlPack);
        }