/// <summary> /// Populate this collection with another collection of items /// </summary> /// <param name="items">The items to populate this collection with</param> private void InternalLoadCollection(IEnumerable <T> items) { Debug.Assert(items != null, "items != null"); #if !PORTABLELIB // For SDP, we must execute the Query implicitly DataServiceQuery <T> query = items as DataServiceQuery <T>; if (query != null) { items = query.Execute() as QueryOperationResponse <T>; } #else Debug.Assert(!(items is DataServiceQuery), "SL Client using DSQ as items...should have been caught by ValidateIteratorParameter."); #endif foreach (T item in items) { // if this is too slow, consider hashing the set // or just use LoadProperties if (!this.Contains(item)) { this.Add(item); } } QueryOperationResponse <T> response = items as QueryOperationResponse <T>; if (response != null) { // this should never be throwing (since we've enumerated already)! // Note: Inner collection's nextPartLinkUri is set by the materializer this.continuation = response.GetContinuation(); } else { this.continuation = null; } }
public void BatchQueriesWithJsonAsync() { var ctx = this.CreateContext(); ctx.Format.UseJson(); var queries = new DataServiceQuery[] { ctx.CreateQuery<Product>("Product"), ctx.Context.Customer.Expand((c) => c.Orders), }; ctx.BeginExecuteBatch( (ar) => { var response = ctx.EndExecuteBatch(ar); Assert.IsTrue(response.IsBatchResponse, "Non-batch response received"); Assert.AreEqual(2, response.Count(), "Unexpected number of operation responses received"); this.EnqueueTestComplete(); }, null, queries); this.WaitForTestToComplete(); }
/// <summary> /// Query object of a function which returns a single item. /// </summary> /// <param name="query">Query object.</param> /// <param name="isComposable">Whether this query is composable.</param> private DataServiceQuerySingle(DataServiceQuery <TElement> query, bool isComposable) { this.Query = query; this.Context = query.Context; this.IsComposable = isComposable; }
/// <summary>Creates and executes a DataServiceQuery based on the passed in expression which results a single value</summary> /// <typeparam name="TElement">generic type</typeparam> /// <param name="expression">The expression for the new query</param> /// <returns>single valued results</returns> internal TElement ReturnSingleton <TElement>(Expression expression) { IQueryable <TElement> query = new DataServiceQuery <TElement> .DataServiceOrderedQuery(expression, this); MethodCallExpression mce = expression as MethodCallExpression; Debug.Assert(mce != null, "mce != null"); SequenceMethod sequenceMethod; if (ReflectionUtil.TryIdentifySequenceMethod(mce.Method, out sequenceMethod)) { switch (sequenceMethod) { case SequenceMethod.Single: return(query.AsEnumerable().Single()); case SequenceMethod.SingleOrDefault: return(query.AsEnumerable().SingleOrDefault()); case SequenceMethod.First: return(query.AsEnumerable().First()); case SequenceMethod.FirstOrDefault: return(query.AsEnumerable().FirstOrDefault()); case SequenceMethod.LongCount: case SequenceMethod.Count: return(((DataServiceQuery <TElement>)query).GetValue(this.Context, ParseQuerySetCount <TElement>)); case SequenceMethod.SumIntSelector: case SequenceMethod.SumDoubleSelector: case SequenceMethod.SumDecimalSelector: case SequenceMethod.SumLongSelector: case SequenceMethod.SumSingleSelector: case SequenceMethod.SumNullableIntSelector: case SequenceMethod.SumNullableDoubleSelector: case SequenceMethod.SumNullableDecimalSelector: case SequenceMethod.SumNullableLongSelector: case SequenceMethod.SumNullableSingleSelector: case SequenceMethod.AverageIntSelector: case SequenceMethod.AverageDoubleSelector: case SequenceMethod.AverageDecimalSelector: case SequenceMethod.AverageLongSelector: case SequenceMethod.AverageSingleSelector: case SequenceMethod.AverageNullableIntSelector: case SequenceMethod.AverageNullableDoubleSelector: case SequenceMethod.AverageNullableDecimalSelector: case SequenceMethod.AverageNullableLongSelector: case SequenceMethod.AverageNullableSingleSelector: case SequenceMethod.MinSelector: // Mapped to a generic expression - Min(IQueryable`1<T0>, Expression`1<Func`2<T0, T1>>)->T1 case SequenceMethod.MaxSelector: // Mapped to a generic expression - Max(IQueryable`1<T0>, Expression`1<Func`2<T0, T1>>)->T1 case SequenceMethod.CountDistinctSelector: // Mapped to a generic expression - CountDistinct(IQueryable`1<T0>, Expression`1<Func`2<T0, T1>>)->Int32 return(((DataServiceQuery <TElement>)query).GetValue(this.Context, this.ParseAggregateSingletonResult <TElement>)); default: throw Error.MethodNotSupported(mce); } } // Should never get here - should be caught by expression compiler. Debug.Assert(false, "Not supported singleton operator not caught by Resource Binder"); throw Error.MethodNotSupported(mce); }
public WebDataQueryWrapper(DataServiceQuery query) { this._DataServiceQuery = query; }