Esempio n. 1
0
        /// <summary>
        /// Executes a query adding to the passed collection.
        /// </summary>
        /// <typeparam name="TColl">The collection <see cref="Type"/>.</typeparam>
        /// <param name="coll">The collection to add items to.</param>
        /// <remarks>The <see cref="QueryArgs"/> <see cref="ODataArgs{T, TModel}.Paging"/> is also applied, including <see cref="PagingArgs.IsGetCount"/> where requested.</remarks>
        public void SelectQuery <TColl>(TColl coll) where TColl : ICollection <T>
        {
            ExecuteQuery(q =>
            {
                ODataFeedAnnotations ann = null !;

                if (QueryArgs.Paging != null)
                {
                    q = q.Skip(QueryArgs.Paging.Skip).Top(QueryArgs.Paging.Take);
                    if (QueryArgs.Paging.IsGetCount && _odata.IsPagingGetCountSupported)
                    {
                        ann = new ODataFeedAnnotations();
                    }
                }

                foreach (var item in q.FindEntriesAsync(ann).GetAwaiter().GetResult())
                {
                    coll.Add(ODataBase.GetValue(QueryArgs, item));
                }

                if (ann != null)
                {
                    QueryArgs.Paging !.TotalCount = ann.Count;
                }
            });
        }
Esempio n. 2
0
        /// <summary>
        /// Batches an <b>execute</b> of an <b>OData</b> request for a specified <paramref name="pathAndQuery"/> using a <see cref="JObject"/> for the request and response.
        /// </summary>
        /// <param name="exeArgs">The <see cref="ODataArgs"/>.</param>
        /// <param name="pathAndQuery">The url path and query <see cref="string"/> (excluding the base URI path).</param>
        /// <param name="json">Optional JSON request content.</param>
        /// <returns>The <see cref="ODataBatchItem"/>.</returns>
        /// <remarks>The <see cref="HttpMethod"/> defaults to a <see cref="HttpMethod.Post"/>. This is overridden using the <see cref="ODataArgs.OverrideHttpMethod"/>.</remarks>
        public async Task <ODataBatchItem> ExecuteAsync(ODataArgs exeArgs, string pathAndQuery, JObject json)
        {
            var obi = AddRequest(await OData.BuildExecuteRequestAsync(exeArgs, pathAndQuery, json).ConfigureAwait(false));

            obi.GetValueFunc = async() => await ODataBase.ProcessExecuteResponseAsync(obi.ResponseMessage, exeArgs).ConfigureAwait(false);

            return(obi);
        }
Esempio n. 3
0
 /// <summary>
 /// Selects first item.
 /// </summary>
 /// <returns>The first item.</returns>
 public T SelectFirst()
 {
     return(ODataBase.GetValue(QueryArgs, ExecuteQuery(q =>
     {
         var coll = q.Skip(0).Top(1).FindEntriesAsync().GetAwaiter().GetResult();
         return coll.First();
     })));
 }
Esempio n. 4
0
 /// <summary>
 /// Selects a single item or default.
 /// </summary>
 /// <returns>The single item or default.</returns>
 public T?SelectSingleOrDefault()
 {
     return(ODataBase.GetValue <T, TModel>(QueryArgs, ExecuteQuery(q =>
     {
         var coll = q.Skip(0).Top(2).FindEntriesAsync().GetAwaiter().GetResult();
         return coll.SingleOrDefault();
     })));
 }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ODataBatchManager"/> class.
 /// </summary>
 /// <param name="odata">The <see cref="ODataBase"/>.</param>
 /// <param name="isChangeSet">Indicates whether the batch is a change set (an atomic unit of work).</param>
 internal ODataBatchManager(ODataBase odata, bool isChangeSet = false)
 {
     OData       = odata ?? throw new ArgumentNullException(nameof(odata));
     IsChangeSet = isChangeSet;
 }
Esempio n. 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ODataQueryable{T}"/> class.
 /// </summary>
 /// <param name="odata">The <see cref="ODataBase"/>.</param>
 /// <param name="queryArgs">The <see cref="ODataArgs"/>.</param>
 /// <param name="executor">The <see cref="IQueryExecutor"/>.</param>
 public ODataQueryable(ODataBase odata, ODataArgs queryArgs, ref IQueryExecutor executor)
     : base(QueryParser.CreateDefault(), CreateExecutor(odata, queryArgs, ref executor))
 {
     QueryExecutor = (ODataQueryExecutor)executor;
 }
Esempio n. 7
0
 /// <summary>
 /// Creates a new <see cref="ODataQueryExecutor"/>.
 /// </summary>
 private static IQueryExecutor CreateExecutor(ODataBase odata, ODataArgs queryArgs, ref IQueryExecutor executor)
 {
     return(executor = new ODataQueryExecutor(odata, queryArgs));
 }
Esempio n. 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ODataQuery{T, TModel}"/> class.
 /// </summary>
 /// <param name="odata">The <see cref="ODataBase"/>.</param>
 /// <param name="queryArgs">The <see cref="ODataArgs{T, TModel}"/>.</param>
 /// <param name="query">A function to modify the underlying <see cref="IQueryable{TModel}"/></param>
 internal ODataQuery(ODataBase odata, ODataArgs <T, TModel> queryArgs, Func <IBoundClient <TModel>, IBoundClient <TModel> >?query = null)
 {
     _odata    = Check.NotNull(odata, nameof(odata));
     QueryArgs = Check.NotNull(queryArgs, nameof(queryArgs));
     _query    = query;
 }