Beispiel #1
0
        private ODataQueryOptions <TModel> GetODataQueryOptions <TModel>(string query) where TModel : class
        {
            if (_oDataQueryOptions == null)
            {
                _oDataQueryOptions = ODataHelpers.GetODataQueryOptions <TModel>
                                     (
                    query,
                    serviceProvider
                                     );
            }

            return((ODataQueryOptions <TModel>)_oDataQueryOptions);
        }
        private ODataQueryOptions <TModel> GetODataQueryOptions <TModel>(string query) where TModel : class
        {
            if (_oDataQueryOptions == null)
            {
                _oDataQueryOptions = ODataHelpers.GetODataQueryOptions <TModel>
                                     (
                    query,
                    serviceProvider,
                    serviceProvider.GetRequiredService <IRouteBuilder>()
                                     );
            }

            return((ODataQueryOptions <TModel>)_oDataQueryOptions);
        }
Beispiel #3
0
        public async void BuildingExpandBuilderTenantExpandCityFilterOnNestedNestedPropertyWithCount()
        {
            string query = "/corebuilding?$top=5&$expand=Builder($expand=City),Tenant&$filter=Builder/City/Name eq 'Leeds'&$count=true";
            ODataQueryOptions <CoreBuilding> options = ODataHelpers.GetODataQueryOptions <CoreBuilding>
                                                       (
                query,
                serviceProvider
                                                       );

            Test(Get <CoreBuilding, TBuilding>(query, options));
            Test(await GetAsync <CoreBuilding, TBuilding>(query, options));

            void Test(ICollection <CoreBuilding> collection)
            {
                Assert.Equal(2, options.Request.ODataFeature().TotalCount);
                Assert.Equal(2, collection.Count);
                Assert.Equal("Leeds", collection.First().Builder.City.Name);
            }
        }
Beispiel #4
0
        public async void BuildingExpandBuilderTenantExpandCityOrderByBuilderNameSkip3Take1NoCount()
        {
            string query = "/corebuilding?$skip=4&$top=1&$expand=Builder($expand=City),Tenant&$orderby=Name desc,Identity";
            ODataQueryOptions <CoreBuilding> options = ODataHelpers.GetODataQueryOptions <CoreBuilding>
                                                       (
                query,
                serviceProvider
                                                       );

            Test(Get <CoreBuilding, TBuilding>(query, options));
            Test(await GetAsync <CoreBuilding, TBuilding>(query, options));

            void Test(ICollection <CoreBuilding> collection)
            {
                Assert.Null(options.Request.ODataFeature().TotalCount);
                Assert.Equal(1, collection.Count);
                Assert.Equal("London", collection.First().Builder.City.Name);
                Assert.Equal("One L1", collection.First().Name);
            }
        }
        private async Task <ICollection <TModel> > Get <TModel, TData>(string query, ODataQueryOptions <TModel> options = null) where TModel : class where TData : class
        {
            return(await DoGet
                   (
                       serviceProvider.GetRequiredService <IMapper>(),
                       serviceProvider.GetRequiredService <MyDbContext>()
                   ));

            async Task <ICollection <TModel> > DoGet(IMapper mapper, MyDbContext context)
            {
                return(await context.Set <TData>().GetAsync
                       (
                           mapper,
                           options ?? ODataHelpers.GetODataQueryOptions <TModel>
                           (
                               query,
                               serviceProvider,
                               serviceProvider.GetRequiredService <IRouteBuilder>()
                           ),
                           HandleNullPropagationOption.False
                       ));
            }
        }