/// <summary> /// Batches a <b>Select query</b> for the <b>OData</b> entity. /// </summary> /// <typeparam name="T">The entity <see cref="Type"/>.</typeparam> /// <param name="query">The <see cref="ODataQueryable{T}"/>.</param> /// <returns>The <see cref="ODataBatchItem"/>.</returns> public async Task <ODataBatchItem> SelectQueryAsync <T>(IQueryable <T> query) { if (query == null) { throw new ArgumentNullException(nameof(query)); } if (!(query is ODataQueryable <T> q)) { throw new ArgumentException("The query must be an instance of ODataQueryable<T>.", nameof(query)); } if (q.QueryExecutor.OData != this.OData) { throw new ArgumentException("The query can only be invoked by this batch where both the batch and query are created by the same ODataBase instance."); } var qa = q.QueryExecutor.GetQueryAggregator(q.Expression, null); var queryArgs = q.QueryExecutor.QueryArgs; var obi = AddRequest(await OData.BuildQueryRequestAsync(queryArgs, q.GetODataQuery(null)).ConfigureAwait(false)); obi.GetValueFunc = async() => { var coll = new List <T>(); await OData.ProcessQueryResponse(obi.ResponseMessage, queryArgs, qa, coll).ConfigureAwait(false); return(coll); }; return(obi); }
/// <summary> /// Creates (<see cref="ODataBase.CreateQuery{T}(ODataArgs)"/>) and batches a <b>Select query</b> for the <b>OData</b> entity. /// </summary> /// <typeparam name="TColl">The collection <see cref="Type"/>.</typeparam> /// <typeparam name="T">The entity <see cref="Type"/>.</typeparam> /// <param name="queryArgs">The <see cref="ODataArgs"/>.</param> /// <param name="query">An optional function to enable in-place query selection.</param> /// <returns>The <see cref="ODataBatchItem"/>.</returns> public async Task <ODataBatchItem> SelectQueryAsync <TColl, T>(ODataArgs queryArgs, Func <IQueryable <T>, IQueryable <T> > query = null) where TColl : ICollection <T>, new() where T : class { var q = OData.CreateQuery <T>(queryArgs); if (query != null) { var q2 = query(q) as ODataQueryable <T>; q = q2 ?? throw new InvalidOperationException("The query function must return an instance of ODataQueryable<T>."); } var qa = q.QueryExecutor.GetQueryAggregator(q.Expression, null); var obi = AddRequest(await OData.BuildQueryRequestAsync(queryArgs, qa.ToString()).ConfigureAwait(false)); obi.GetValueFunc = async() => { var coll = new TColl(); await OData.ProcessQueryResponse(obi.ResponseMessage, queryArgs, qa, coll).ConfigureAwait(false); return(coll); }; return(obi); }