コード例 #1
0
        /// <summary>
        /// GroupBy
        /// </summary>
        /// <param name="expression">表达式树</param>
        /// <param name="sqlPack">sql打包对象</param>
        /// <returns>SqlPack</returns>
        public override SqlPack GroupBy(ConstantExpression expression, SqlPack sqlPack)
        {
            var tableName = sqlPack.GetTableName(sqlPack.DefaultType);

            sqlPack.SetTableAlias(tableName);
            var tableAlias = sqlPack.GetTableAlias(tableName);

            if (!tableAlias.IsNullOrEmpty())
            {
                tableAlias += ".";
            }
            sqlPack += tableAlias + sqlPack.GetColumnName(expression.Value.ToString()) + ",";
            return(sqlPack);
        }
コード例 #2
0
        /// <summary>
        /// OrderBy
        /// </summary>
        /// <param name="expression">表达式树</param>
        /// <param name="sqlPack">sql打包对象</param>
        /// <param name="orders">排序方式</param>
        /// <returns>SqlPack</returns>
        public override SqlPack OrderBy(ConstantExpression expression, SqlPack sqlPack, params OrderType[] orders)
        {
            var tableName = sqlPack.GetTableName(sqlPack.DefaultType);

            sqlPack.SetTableAlias(tableName);
            var tableAlias = sqlPack.GetTableAlias(tableName);

            if (!tableAlias.IsNullOrEmpty())
            {
                tableAlias += ".";
            }
            var field = expression.Value.ToString();

            if (!field.ToUpper().Contains(" ASC") && !field.ToUpper().Contains(" DESC"))
            {
                field = sqlPack.GetColumnName(field);
            }
            sqlPack += tableAlias + field;
            if (orders?.Length > 0)
            {
                sqlPack += $" { (orders[0] == OrderType.Descending ? "DESC" : "ASC")}";
            }
            return(sqlPack);
        }