Esempio n. 1
0
        /// <summary>
        /// GroupBy
        /// </summary>
        /// <param name="expression">表达式树</param>
        /// <param name="sqlWrapper">sql打包对象</param>
        /// <returns>SqlWrapper</returns>
        public override SqlWrapper GroupBy(NewArrayExpression expression, SqlWrapper sqlWrapper)
        {
            for (var i = 0; i < expression.Expressions.Count; i++)
            {
                SqlExpressionProvider.GroupBy(expression.Expressions[i], sqlWrapper);
            }

            sqlWrapper.Remove(sqlWrapper.Length - 1, 1);

            return(sqlWrapper);
        }
        /// <summary>
        /// GroupBy
        /// </summary>
        /// <param name="expression">表达式树</param>
        /// <param name="sqlWrapper">sql打包对象</param>
        /// <returns>SqlWrapper</returns>
        public override SqlWrapper GroupBy(NewExpression expression, SqlWrapper sqlWrapper)
        {
            foreach (Expression item in expression.Arguments)
            {
                SqlExpressionProvider.GroupBy(item, sqlWrapper);
                sqlWrapper += ",";
            }

            sqlWrapper.Remove(sqlWrapper.Length - 1, 1);

            return(sqlWrapper);
        }
        /// <summary>
        /// GroupBy
        /// </summary>
        /// <param name="expression">表达式树</param>
        /// <param name="sqlWrapper">sql包装器</param>
        /// <returns>SqlWrapper</returns>
        public override SqlWrapper GroupBy(NewArrayExpression expression, SqlWrapper sqlWrapper)
        {
            for (var i = 0; i < expression.Expressions.Count; i++)
            {
                SqlExpressionProvider.GroupBy(expression.Expressions[i], sqlWrapper);

                sqlWrapper += ",";
            }

            sqlWrapper.RemoveLast(',');

            return(sqlWrapper);
        }
Esempio n. 4
0
        /// <summary>
        /// GroupBy
        /// </summary>
        /// <param name="expression">表达式树</param>
        /// <param name="sqlWrapper">sql打包对象</param>
        /// <returns>SqlWrapper</returns>
        public override SqlWrapper GroupBy(ListInitExpression expression, SqlWrapper sqlWrapper)
        {
            var array = (expression.ToObject() as IEnumerable <object>)?.ToList();

            if (array != null)
            {
                for (var i = 0; i < array.Count; i++)
                {
                    SqlExpressionProvider.GroupBy(Expression.Constant(array[i], array[i].GetType()), sqlWrapper);
                }
                sqlWrapper.Remove(sqlWrapper.Length - 1, 1);
            }

            return(sqlWrapper);
        }
        /// <summary>
        /// GroupBy
        /// </summary>
        /// <param name="expression">表达式树</param>
        /// <param name="sqlWrapper">sql打包对象</param>
        /// <returns>SqlWrapper</returns>
        public override SqlWrapper GroupBy(MemberExpression expression, SqlWrapper sqlWrapper)
        {
            var tableAlias = string.Empty;
            var tableName  = string.Empty;

            if (expression.Expression.NodeType == ExpressionType.Parameter)
            {
                var type = expression.Expression.Type != expression.Member.DeclaringType ?
                           expression.Expression.Type :
                           expression.Member.DeclaringType;
                tableName  = sqlWrapper.GetTableName(type);
                tableAlias = (expression.Expression as ParameterExpression)?.Name;
            }

            if (expression.Expression.NodeType == ExpressionType.Constant)
            {
                tableName = sqlWrapper.GetTableName(sqlWrapper.DefaultType);
            }

            tableAlias = sqlWrapper.GetTableAlias(tableName, tableAlias);

            if (!tableAlias.IsNullOrEmpty())
            {
                tableAlias += ".";
            }

            if (expression.Expression.NodeType == ExpressionType.Parameter)
            {
                sqlWrapper += tableAlias + sqlWrapper.GetColumnInfo(expression.Member.DeclaringType, expression.Member).columnName;
            }

            if (expression.Expression.NodeType == ExpressionType.Constant)
            {
                var obj = expression.ToObject();
                if (obj != null)
                {
                    var type = obj.GetType().Name;

                    if (type == "String[]" && obj is string[] array)
                    {
                        foreach (var item in array)
                        {
                            SqlExpressionProvider.GroupBy(Expression.Constant(item, item.GetType()), sqlWrapper);
                        }
                        sqlWrapper.Remove(sqlWrapper.Length - 1, 1);
                    }

                    if (type == "List`1" && obj is List <string> list)
                    {
                        foreach (var item in list)
                        {
                            SqlExpressionProvider.GroupBy(Expression.Constant(item, item.GetType()), sqlWrapper);
                        }
                        sqlWrapper.Remove(sqlWrapper.Length - 1, 1);
                    }

                    if (type == "String" && obj is string str)
                    {
                        SqlExpressionProvider.GroupBy(Expression.Constant(str, str.GetType()), sqlWrapper);
                        sqlWrapper.Remove(sqlWrapper.Length - 1, 1);
                    }
                }
            }

            return(sqlWrapper);
        }
Esempio n. 6
0
        /// <summary>
        /// GroupBy
        /// </summary>
        /// <param name="expression">表达式树</param>
        /// <param name="sqlWrapper">sql打包对象</param>
        /// <returns>SqlWrapper</returns>
        public override SqlWrapper GroupBy(UnaryExpression expression, SqlWrapper sqlWrapper)
        {
            SqlExpressionProvider.GroupBy(expression.Operand, sqlWrapper);

            return(sqlWrapper);
        }