Ejemplo n.º 1
0
 /// <summary>
 /// GroupBy
 /// </summary>
 /// <param name="expression">表达式树</param>
 /// <param name="sqlPack">sql打包对象</param>
 /// <returns>SqlPack</returns>
 public override SqlPack GroupBy(NewArrayExpression expression, SqlPack sqlPack)
 {
     for (var i = 0; i < expression.Expressions.Count; i++)
     {
         SqlBuilderProvider.GroupBy(expression.Expressions[i], sqlPack);
     }
     sqlPack.Sql.Remove(sqlPack.Length - 1, 1);
     return(sqlPack);
 }
 /// <summary>
 /// GroupBy
 /// </summary>
 /// <param name="expression">表达式树</param>
 /// <param name="sqlPack">sql打包对象</param>
 /// <returns>SqlPack</returns>
 public override SqlPack GroupBy(NewExpression expression, SqlPack sqlPack)
 {
     foreach (Expression item in expression.Arguments)
     {
         SqlBuilderProvider.GroupBy(item, sqlPack);
     }
     sqlPack.Sql.Remove(sqlPack.Length - 1, 1);
     return(sqlPack);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// GroupBy
        /// </summary>
        /// <param name="expression">表达式树</param>
        /// <param name="sqlPack">sql打包对象</param>
        /// <returns>SqlPack</returns>
        public override SqlPack GroupBy(MemberExpression expression, SqlPack sqlPack)
        {
            string tableName = string.Empty;

            if (expression.Expression.NodeType == ExpressionType.Parameter)
            {
                var type = expression.Expression.Type != expression.Member.DeclaringType ?
                           expression.Expression.Type :
                           expression.Member.DeclaringType;
                tableName = sqlPack.GetTableName(type);
            }
            if (expression.Expression.NodeType == ExpressionType.Constant)
            {
                tableName = sqlPack.GetTableName(sqlPack.DefaultType);
            }
            sqlPack.SetTableAlias(tableName);
            var tableAlias = sqlPack.GetTableAlias(tableName);

            if (!tableAlias.IsNullOrEmpty())
            {
                tableAlias += ".";
            }
            if (expression.Expression.NodeType == ExpressionType.Parameter)
            {
                sqlPack += tableAlias + sqlPack.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)
                        {
                            SqlBuilderProvider.GroupBy(Expression.Constant(item, item.GetType()), sqlPack);
                        }
                        sqlPack.Sql.Remove(sqlPack.Length - 1, 1);
                    }
                    if (type == "List`1" && obj is List <string> list)
                    {
                        foreach (var item in list)
                        {
                            SqlBuilderProvider.GroupBy(Expression.Constant(item, item.GetType()), sqlPack);
                        }
                        sqlPack.Sql.Remove(sqlPack.Length - 1, 1);
                    }
                    if (type == "String" && obj is string str)
                    {
                        SqlBuilderProvider.GroupBy(Expression.Constant(str, str.GetType()), sqlPack);
                        sqlPack.Sql.Remove(sqlPack.Length - 1, 1);
                    }
                }
            }
            return(sqlPack);
        }
        /// <summary>
        /// GroupBy
        /// </summary>
        /// <param name="expression">表达式树</param>
        /// <param name="sqlPack">sql打包对象</param>
        /// <returns>SqlPack</returns>
        public override SqlPack GroupBy(ListInitExpression expression, SqlPack sqlPack)
        {
            var array = (expression.ToObject() as IEnumerable <object>)?.ToList();

            if (array != null)
            {
                for (var i = 0; i < array.Count; i++)
                {
                    SqlBuilderProvider.GroupBy(Expression.Constant(array[i], array[i].GetType()), sqlPack);
                }
                sqlPack.Sql.Remove(sqlPack.Length - 1, 1);
            }
            return(sqlPack);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// GroupBy
 /// </summary>
 /// <param name="expression">表达式树</param>
 /// <param name="sqlPack">sql打包对象</param>
 /// <returns>SqlPack</returns>
 public override SqlPack GroupBy(UnaryExpression expression, SqlPack sqlPack)
 {
     SqlBuilderProvider.GroupBy(expression.Operand, sqlPack);
     return(sqlPack);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// GroupBy
 /// </summary>
 /// <param name="expression">表达式树</param>
 /// <returns>SqlBuilderCore</returns>
 public SqlBuilderCore <T> GroupBy(Expression <Func <T, object> > expression)
 {
     this._sqlPack += " GROUP BY ";
     SqlBuilderProvider.GroupBy(expression.Body, this._sqlPack);
     return(this);
 }