/// <inheritdoc />
        public virtual IReadOnlyDapperRepository <TEntity> SetOrderBy(OrderInfo.SortDirection direction, params string[] cols)
        {
            var order = FilterData.OrderInfo ?? new OrderInfo();

            order.Direction = direction;
            order.Columns   = cols.ToList();

            FilterData.OrderInfo = order;

            return(this);
        }
コード例 #2
0
        /// <inheritdoc />
        public virtual IReadOnlyDapperRepository <TEntity> SetOrderBy <T>(OrderInfo.SortDirection direction, bool permanent,
                                                                          Expression <Func <T, object> > expr)
        {
            var order = FilterData.OrderInfo ?? new OrderInfo();

            order.Direction = direction;

            var type = typeof(T);

            switch (expr.Body.NodeType)
            {
            case ExpressionType.Convert:
            {
                if (expr.Body is UnaryExpression lambdaUnary)
                {
                    var expression = lambdaUnary.Operand as MemberExpression;
                    order.Columns = new List <string> {
                        GetProperty(expression, type)
                    };
                }

                break;
            }

            case ExpressionType.MemberAccess:
                order.Columns = new List <string> {
                    GetProperty(expr.Body, type)
                };
                break;

            default:
            {
                var cols = (expr.Body as NewExpression)?.Arguments;
                if (cols != null)
                {
                    var propertyNames = cols.Select(expression => GetProperty(expression, type)).ToList();
                    order.Columns = propertyNames;
                }

                break;
            }
            }

            order.Permanent = permanent;

            FilterData.OrderInfo = order;

            return(this);
        }
コード例 #3
0
        /// <inheritdoc />
        public virtual ReadOnlyDapperRepository <TEntity> SetOrderBy(OrderInfo.SortDirection direction, bool permanent,
                                                                     params Expression <Func <TEntity, object> >[] cols)
        {
            var type = typeof(TEntity);

            var propertyNames =
                (from s in cols
                 select ExpressionHelper.GetPropertyName(s)
                 into prop
                 let attr = type.GetProperty(prop)?.GetCustomAttribute <ColumnAttribute>()
                            select attr == null ? prop : attr.Name).ToList();

            var order = SqlGenerator.FilterData.OrderInfo ?? new OrderInfo();

            order.Direction = direction;
            order.Columns   = propertyNames;
            order.Permanent = permanent;

            SqlGenerator.FilterData.OrderInfo = order;

            return(this);
        }
        /// <inheritdoc />
        public virtual IReadOnlyDapperRepository <TEntity> SetOrderBy <T>(OrderInfo.SortDirection direction, bool permanent,
                                                                          Expression <Func <T, object> > expr)
        {
            var order = FilterData.OrderInfo ?? new OrderInfo();

            order.Direction = direction;

            var type = typeof(T);

            switch (expr.Body.NodeType)
            {
            case ExpressionType.Convert:
            {
                if (expr.Body is UnaryExpression {
                        Operand : MemberExpression expression
                    })
                {
                    order.Columns = new List <string> {
                        GetProperty(expression, type)
                    };
                }

                break;
            }
コード例 #5
0
 /// <inheritdoc />
 public virtual ReadOnlyDapperRepository <TEntity> SetOrderBy(OrderInfo.SortDirection direction, params Expression <Func <TEntity, object> >[] cols)
 {
     return(SetOrderBy(direction, false, cols));
 }
 /// <inheritdoc />
 public virtual IReadOnlyDapperRepository <TEntity> SetOrderBy(OrderInfo.SortDirection direction, Expression <Func <TEntity, object> > expr)
 {
     return(SetOrderBy(direction, false, expr));
 }