/// <summary> /// Orders the collection by applying given ordering. /// </summary> /// <param name="ordering">The ordering to use.</param> /// <returns>Ordered collection.</returns> /// <remarks>This overload allows for more intellisense-friendly way of specifying ordering.</remarks> public QueryCollectionValue OrderBy(QueryOrdering ordering) { ExceptionUtilities.CheckArgumentNotNull(ordering, "ordering"); ExceptionUtilities.CheckCollectionNotEmpty(ordering.Selectors, "ordering.Selectors"); if (this.IsNull) { return(this); } IEnumerable <QueryValue> orderedElements = ordering.Apply(this.Elements.Cast <object>()).Cast <QueryValue>(); QueryError currentError = QueryError.Combine(this.EvaluationError, QueryError.GetErrorFromValues(orderedElements)); if (currentError != null) { return((QueryCollectionValue)this.Type.CreateErrorValue(currentError)); } // if this collection contains duplicate order by key selectors if (HasNondeterministicOrdering(ordering, orderedElements)) { return(new QueryCollectionValue(this.Type, this.EvaluationStrategy, null, orderedElements, false)); } else { return(new QueryCollectionValue(this.Type, this.EvaluationStrategy, null, orderedElements, true)); } }
private QueryScalarValue EvaluateBinaryOperation(QueryScalarValue otherValue, QueryBinaryOperation operation) { ExceptionUtilities.CheckArgumentNotNull(otherValue, "otherValue"); var result = this.EvaluationStrategy.Evaluate(operation, this, otherValue); var error = QueryError.Combine(this.EvaluationError, otherValue.EvaluationError); if (error != null) { result.EvaluationError = error; } return(result); }
/// <summary> /// Applies the Take operation on the given collection. /// </summary> /// <param name="takeCount">How many elements to take.</param> /// <returns>Collection with the applied Take operation.</returns> public QueryCollectionValue Take(QueryScalarValue takeCount) { ExceptionUtilities.CheckArgumentNotNull(takeCount, "takeCount"); QueryError currentError = QueryError.Combine(this.EvaluationError, takeCount.EvaluationError); if (currentError != null) { return((QueryCollectionValue)this.Type.CreateErrorValue(currentError)); } IEnumerable <QueryValue> result = null; if (!this.IsNull) { result = this.Elements.Take((int)takeCount.Value).ToList(); } return(new QueryCollectionValue(this.Type, this.Type.EvaluationStrategy, QueryError.GetErrorFromValues(result), result, this.IsSorted)); }
/// <summary> /// Applies the Skip operation on the given collection. /// </summary> /// <param name="skipCount">How many elements to skip.</param> /// <returns>Collection with the applied Skip operation.</returns> public QueryCollectionValue Skip(QueryScalarValue skipCount) { ExceptionUtilities.CheckArgumentNotNull(skipCount, "skipCount"); QueryError currentError = QueryError.Combine(this.EvaluationError, skipCount.EvaluationError); if (currentError != null) { return((QueryCollectionValue)this.Type.CreateErrorValue(currentError)); } IEnumerable <QueryValue> result = null; if (!this.IsNull) { // perhaps this must be changed - moved to EvaluationStrategy result = this.Elements.Skip((int)skipCount.Value); } return(new QueryCollectionValue(this.Type, this.Type.EvaluationStrategy, QueryError.GetErrorFromValues(result), result, this.IsSorted)); }