/// <summary> /// Wrap the DSPLinqQuery with a PagedQueryProvider /// </summary> /// <param name="source">The DSPLinqQuery Instance</param> /// <returns>A new queryable which supports paging</returns> private IQueryable WrapWithPagingProvider(IQueryable source) { if (customPagingEnabled) { IQueryProvider provider = new AstoriaUnitTests.Tests.PagedQueryProvider( this, source.Provider, null, null, new AstoriaUnitTests.Tests.CountManager()); return(DSPLinqQueryProvider.CreateQuery(provider, source.Expression)); } else { return(source); } }
/// <summary>Invokes the specified service operation.</summary> /// <param name="serviceOperation">The service operation to invoke.</param> /// <param name="parameters">The parameters for the service operation. Their types will match the types of the declared parameters for the service operation.</param> /// <returns>The result of the service operation. /// If the service operation is declared to return void, this method should return null. /// Otherwise the method should return object of the type declared as the return type for the service operation.</returns> public object InvokeServiceOperation(ServiceOperation serviceOperation, object[] parameters) { Func <Object[], Object> operation; if (this.dataSource.ServiceOperations.TryGetValue(serviceOperation.Name, out operation)) { object result = operation(parameters); if (result is IQueryable) { // in order to further compose on top of this query, we need to turn this into a DSPLinqQuery return(WrapWithPagingProvider(DSPLinqQueryProvider.CreateQuery((IQueryable)result))); } return(result); } throw new InvalidOperationException("Specified service operation is not implemented by the data source"); }
/// <summary>Internal constructor.</summary> /// <param name="queryProvider">The query provider to use for this query.</param> /// <param name="queryExpression">The query expression for this query (the DSP version).</param> internal DSPLinqQuery(DSPLinqQueryProvider queryProvider, Expression queryExpression) { this.queryProvider = queryProvider; this.queryExpression = queryExpression; }
/// <summary>Helper strongly typed method to create the query for a resource set root.</summary> /// <typeparam name="TElement">The instance type of a single resource in the set.</typeparam> /// <param name="resourceSet">The resource set to get the query root for.</param> /// <returns>Strongly typed query for the resource set root.</returns> private System.Linq.IQueryable GetTypedQueryRootForResourceSet <TElement>(ResourceSet resourceSet) { IQueryable source = DSPLinqQueryProvider.CreateQuery(this.dataSource.GetResourceSetEntities(resourceSet.Name).Cast <TElement>().AsQueryable()); return(WrapWithPagingProvider(source)); }
/// <summary>Wraps a query in a new query which will translate the DSP query into a LINQ to Objects runnable query /// and run it on the provided <paramref name="underlyingQuery"/>.</summary> /// <param name="underlyingQuery">The underlying (LINQ to Objects) query to wrap.</param> /// <returns>A new query which can handle the DSP expressions and run them on top of the <pararef name="underlyingQuery"/>.</returns> public static IQueryable CreateQuery(IQueryable underlyingQuery) { DSPLinqQueryProvider provider = new DSPLinqQueryProvider(underlyingQuery.Provider); return(CreateQuery(provider, underlyingQuery.Expression)); }