Ejemplo n.º 1
0
    /// <summary>
    /// Initializes a new instance of the <see cref="Ordering"/> class.
    /// </summary>
    /// <param name="expression">The expression used to order the data items returned by the query.</param>
    /// <param name="direction">The <see cref="OrderingDirection"/> to use for sorting.</param>
    public Ordering (Expression expression, OrderingDirection direction)
    {
      ArgumentUtility.CheckNotNull ("expression", expression);

      _expression = expression;
      OrderingDirection = direction;
    }
Ejemplo n.º 2
0
        public virtual AliasExpression AddToOrderBy(
            [NotNull] string column,
            [NotNull] IProperty property,
            [NotNull] TableExpressionBase table,
            OrderingDirection orderingDirection)
        {
            Check.NotEmpty(column, nameof(column));
            Check.NotNull(property, nameof(property));
            Check.NotNull(table, nameof(table));

            var columnExpression = new ColumnExpression(column, property, table);
            var aliasExpression  = new AliasExpression(columnExpression);

            if (_orderBy.FindIndex(o => o.Expression.TryGetColumnExpression()?.Equals(columnExpression) ?? false) == -1)
            {
                _orderBy.Add(new Ordering(aliasExpression, orderingDirection));
            }

            return(aliasExpression);
        }
Ejemplo n.º 3
0
        public virtual ColumnExpression AddToOrderBy(
            [NotNull] string column,
            [NotNull] IProperty property,
            [NotNull] IQuerySource querySource,
            OrderingDirection orderingDirection)
        {
            Check.NotEmpty(column, "column");
            Check.NotNull(property, "property");
            Check.NotNull(property, "querySource");

            var columnExpression
                = new ColumnExpression(
                      column,
                      property,
                      FindTableForQuerySource(querySource));

            if (_orderBy.FindIndex(o => o.Expression.Equals(columnExpression)) == -1)
            {
                _orderBy.Add(new Ordering(columnExpression, orderingDirection));
            }

            return(columnExpression);
        }
Ejemplo n.º 4
0
        public virtual void AddToOrderBy([NotNull] IProperty property, OrderingDirection orderingDirection)
        {
            Check.NotNull(property, "property");

            _orderByList.Add(Tuple.Create(property, orderingDirection));
        }
Ejemplo n.º 5
0
            public static string GetStatement(Parameters parameters, Expression expression, OrderingDirection orderingDirection)
            {
                var expressionVisitor = new OrderByExpressionVisitor(parameters);

                expressionVisitor.VisitExpression(expression);

                if (orderingDirection == OrderingDirection.Desc)
                {
                    expressionVisitor.Statement.Append(" desc");
                }

                return(expressionVisitor.GetStatement());
            }
 private static IOrderedAsyncEnumerable <TSource> ThenByShim <TSource, TKey>(
     IOrderedAsyncEnumerable <TSource> source, Func <TSource, TKey> expression, OrderingDirection orderingDirection)
 {
     return(orderingDirection == OrderingDirection.Asc
         ? source.ThenBy(expression)
         : source.ThenByDescending(expression));
 }
 public void OrderBy(PropertyPath path, OrderingDirection direction)
 {
     _orderings.Add(new EmbeddedIndexOrdering(path, direction));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Create a new ordering clause
 /// </summary>
 /// <param name="selectorExpression">The expression used for sorting</param>
 /// <param name="orderingDirection">The sort direction</param>
 public SparqlOrdering(string selectorExpression, OrderingDirection orderingDirection)
 {
     SelectorExpression = selectorExpression;
     OrderingDirection = orderingDirection;
 }
 private void ExpectSortOnProperty(string propertyName, int sortType, OrderingDirection direction)
 {
     var mappingInfo = MockRepository.GenerateStub<IFieldMappingInfo>();
     mappingProvider.Expect(m => m.GetMappingInfo(propertyName)).Return(mappingInfo);
     mappingInfo.Stub(i => i.FieldName).Return(propertyName);
     mappingInfo.Stub(i => i.CreateSortField(direction == OrderingDirection.Desc)).Return(new SortField(propertyName, sortType, direction == OrderingDirection.Desc));
 }
Ejemplo n.º 10
0
 internal void Parse(Ordering ordering)
 {
     direction = ordering.OrderingDirection;
     Visit(ordering.Expression);
 }
Ejemplo n.º 11
0
        public virtual ColumnExpression AddToOrderBy(
            [NotNull] IProperty property,
            [NotNull] IQuerySource querySource,
            OrderingDirection orderingDirection)
        {
            Check.NotNull(property, "property");
            Check.NotNull(property, "querySource");

            var columnExpression
                = new ColumnExpression(property, FindTableForQuerySource(querySource).Alias);

            _orderBy.Add(new Ordering(columnExpression, orderingDirection));

            return columnExpression;
        }
 private void AssertSortFieldEquals(SortField sortField, string expectedFieldName, OrderingDirection expectedDirection, int expectedType)
 {
     Assert.That(sortField.Field, Is.EqualTo(expectedFieldName));
     Assert.That(sortField.Type, Is.EqualTo(expectedType), "SortField type for field " + expectedFieldName);
     Assert.That(sortField.Reverse, Is.EqualTo(expectedDirection == OrderingDirection.Desc), "Reverse");
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Ordering"/> class.
 /// </summary>
 /// <param name="expression">The expression used to order the data items returned by the query.</param>
 /// <param name="direction">The <see cref="OrderingDirection"/> to use for sorting.</param>
 public Ordering(Expression expression, OrderingDirection direction)
 {
     _expression       = expression;
     OrderingDirection = direction;
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Create a new ordering clause
 /// </summary>
 /// <param name="selectorExpression">The expression used for sorting</param>
 /// <param name="orderingDirection">The sort direction</param>
 public SparqlOrdering(string selectorExpression, OrderingDirection orderingDirection)
 {
     SelectorExpression = selectorExpression;
     OrderingDirection  = orderingDirection;
 }
Ejemplo n.º 15
0
 public static IQueryable <TSource> OrderByWithDirection <TSource, TKey>(this IQueryable <TSource> query,
                                                                         Expression <Func <TSource, TKey> > keySelector,
                                                                         OrderingDirection direction)
 => direction switch
 {
Ejemplo n.º 16
0
 internal static IOrderedEnumerable <TSource> _OrderBy <TSource, TKey>(
     IEnumerable <TSource> source, Func <TSource, TKey> expression, OrderingDirection orderingDirection)
 => orderingDirection == OrderingDirection.Asc
         ? source.OrderBy(expression)
         : source.OrderByDescending(expression);
Ejemplo n.º 17
0
        public virtual AliasExpression AddToOrderBy(
            [NotNull] string column,
            [NotNull] IProperty property,
            [NotNull] TableExpressionBase table,
            OrderingDirection orderingDirection)
        {
            Check.NotEmpty(column, nameof(column));
            Check.NotNull(property, nameof(property));
            Check.NotNull(table, nameof(table));

            var columnExpression = new ColumnExpression(column, property, table);
            var aliasExpression = new AliasExpression(columnExpression);

            if (_orderBy.FindIndex(o => o.Expression.TryGetColumnExpression()?.Equals(columnExpression) ?? false) == -1)
            {
                _orderBy.Add(new Ordering(aliasExpression, orderingDirection));
            }

            return aliasExpression;
        }
Ejemplo n.º 18
0
 // ReSharper disable once InconsistentNaming
 private static IOrderedEnumerable <TSource> _ThenBy <TSource, TKey>(
     IOrderedEnumerable <TSource> source, Func <TSource, TKey> expression, OrderingDirection orderingDirection)
 => orderingDirection == OrderingDirection.Asc
         ? source.ThenBy(expression)
         : source.ThenByDescending(expression);
Ejemplo n.º 19
0
 public OrderProperties(string propertyName, Type propertyType, OrderingDirection direction)
 {
     PropertyType      = propertyType;
     PropertyName      = propertyName;
     OrderingDirection = direction;
 }
Ejemplo n.º 20
0
 public OrderingExpression(PropertyPath path, Expression expression, OrderingDirection direction)
 {
     _path = path;
     _expression = expression;
     _direction = direction;
 }
        public static string GetStatement(DataContext dbContext, SqlParameterCollection parameters, Expression expression, OrderingDirection orderingDirection)
        {
            var expressionVisitor = new OrderByExpressionVisitor(dbContext, parameters);

            expressionVisitor.Visit(expression);

            if (orderingDirection == OrderingDirection.Desc)
            {
                expressionVisitor.Statement.Append(" desc");
            }

            return(expressionVisitor.GetStatement());
        }
Ejemplo n.º 22
0
 private void AssertSortFieldEquals(SortField sortField, string expectedFieldName, OrderingDirection expectedDirection, int expectedType)
 {
     Assert.That(sortField.Field, Is.EqualTo(expectedFieldName));
     Assert.That(sortField.Type, Is.EqualTo(expectedType), "SortField type for field " + expectedFieldName);
     Assert.That(sortField.Reverse, Is.EqualTo(expectedDirection == OrderingDirection.Desc), "Reverse");
 }
Ejemplo n.º 23
0
 public EmbeddedIndexOrdering(PropertyPath path, OrderingDirection direction)
 {
     _path = path;
     _direction = direction;
 }