コード例 #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            var model = EdmModelBuilder.GetEdmModel();

            app.UseMvc(builder =>
            {
                builder.Select().Expand().Filter().OrderBy().MaxTop(100).Count();

                builder.MapRoute(
                    name: "default",
                    template: "",
                    defaults: new { controller = "Home", action = "Index" });
                builder.EnableDependencyInjection();

                builder.MapODataServiceRoute("odata1", "efcore", model);

                builder.MapODataServiceRoute("odata2", "inmem", model);

                builder.MapODataServiceRoute("odata3", "composite", EdmModelBuilder.GetCompositeModel());

                builder.MapODataServiceRoute("odata4", "odata", EdmModelBuilder.GetCustomerOrderModel());
            });
        }
コード例 #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();
            app.UseAuthorization();

            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            });

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            app.EnsureMigrationOfContext <ContactDbContext>();

            app.UseODataMvc(EdmModelBuilder.GetEdmModel());
        }
コード例 #3
0
ファイル: TestModelSource.cs プロジェクト: 2gis/nuclear-river
        static TestModelSource()
        {
            BoundedContextElement context = BoundedContextElement.Config
                .Name("Context")
                .ConceptualModel(
                    StructuralModelElement.Config
                    .Types((EnumTypeElement)EnumTypeElement.Config.Name("EnumType").Member("Member1", 0).Member("Member2", 1))
                    .Elements(
                        EntityElement.Config
                            .Name("MasterClass")
                            .HasKey("Id")
                            .Property(EntityPropertyElement.Config.Name("Id").OfType(ElementaryTypeKind.Int32))
                            .Property(EntityPropertyElement.Config.Name("Name").OfType(ElementaryTypeKind.String))
                            .Property(EntityPropertyElement.Config.Name("EnumType").OfType<EnumTypeElement>(EnumTypeElement.Config.Name("EnumType")))
                            .Relation(EntityRelationElement.Config
                                .Name("NestedClass")
                                .DirectTo(
                                    EntityElement.Config
                                        .Name("NestedClass")
                                        .HasKey("Id")
                                        .Property(EntityPropertyElement.Config.Name("Id").OfType(ElementaryTypeKind.Int32))
                                        .Property(EntityPropertyElement.Config.Name("Name").OfType(ElementaryTypeKind.String)))
                             .AsOne())));

            var provider = CreateProvider(MockSource(context));
            var contextId = context.Identity.Id;

            var edmModelBuilder = new EdmModelBuilder(provider, new EdmModelAnnotator(ClrTypes));
            EdmModel = edmModelBuilder.Build()[contextId];
        }
コード例 #4
0
ファイル: Startup.cs プロジェクト: strandman/WebApiSample
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            IEdmModel model = EdmModelBuilder.GetEdmModel();

            app.UseRouting();

            app.UseAuthorization();

            app.UseODataBatching();

            app.UseEndpoints(endpoints =>
            {
                endpoints.Select().Expand().Filter().OrderBy().MaxTop(100).Count();

                endpoints.MapODataRoute("nullPrefix", null, model);

                endpoints.MapODataRoute("odataPrefix", "odata", model);

                endpoints.MapODataRoute("myPrefix", "my/{data}", model);

                endpoints.MapODataRoute("msPrefix", "ms", model, new DefaultODataBatchHandler());
            });

            app.UseSwagger();

            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("v1/swagger.json", "Test API (V1)");
            });
        }
コード例 #5
0
ファイル: Startup.cs プロジェクト: biitheck/CrossBridgeTest
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env,
                              EdmModelBuilder modelBuilder,
                              AppDbContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }

            DbInitializer.Initialize(context, env);

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");

                // OData.
                routes.MapODataServiceRoute("ODataRoutes",
                                            "odata",
                                            modelBuilder.GetEdmModel(app.ApplicationServices));
            });
        }
コード例 #6
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }

            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthorization();

            app.UseMvc(routeBuilder =>
            {
                routeBuilder.Select().Expand().Filter().OrderBy().MaxTop(100).Count();
                routeBuilder.EnableDependencyInjection();
                IEdmModel model = EdmModelBuilder.GetEdmModel();
                routeBuilder.MapODataServiceRoute("odata", "odata", model);
            });
        }
コード例 #7
0
ファイル: WebApiConfig.cs プロジェクト: xuzhg/MyAspNetCore
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            CustomerGeoContext.Init();

            config.MapODataServiceRoute("odata", "odata", EdmModelBuilder.BuildCustomerEdmModel());
        }
コード例 #8
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            IEdmModel model = EdmModelBuilder.GetEdmModel();

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseMvc(routeBuilder =>
            {
                routeBuilder.Select().Expand().Filter().OrderBy();
                routeBuilder.MapODataServiceRoute("odata", "odata", model);
            });

            //app.UseEndpoints(endpoints =>
            //{
            //    //endpoints.MapControllers();
            //    endpoints.MapODataRoute("odataPrefix", "odata", model);
            //});
        }
コード例 #9
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });


            app.UseMvc(builder =>
            {
                builder.Select().Expand().Filter().OrderBy().MaxTop(80).Count();

                builder.MapODataServiceRoute("odata", "odata", EdmModelBuilder.GetEdmModel());
            });
        }
コード例 #10
0
        //[EnableQuery]
        public IActionResult Get(ODataQueryOptions <Customer> queryOptions)
        {
            if (queryOptions.Filter != null)
            {
                var              model     = EdmModelBuilder.GetEdmModel2();
                IEdmEntitySet    entitySet = model.EntityContainer.FindEntitySet("Customers");
                EntitySetSegment segment   = new EntitySetSegment(entitySet);
                ODataPath        path      = new ODataPath(segment);
                //        Request.ODataFeature().Model = model; // if you have these codes, the output is different
                //       Request.ODataFeature().Path = path;
                ODataQueryContext context = new ODataQueryContext(model, typeof(Customer), path);

                // I hard code the rawValue, you should retrieve the filter clause from queryOptions to construct the it.
                string rawValue = "contains(CustomMetadata, 'CustomPropA')";

                ODataQueryOptionParser parser = new ODataQueryOptionParser(model, path, new Dictionary <string, string>
                {
                    { "$filter", rawValue }
                });

                FilterQueryOption filter = new FilterQueryOption(rawValue, context, parser);
                return(Ok(filter.ApplyTo(_context.Customers, new ODataQuerySettings())));
            }

            return(Ok(_context.Customers));
        }
コード例 #11
0
ファイル: Startup.cs プロジェクト: smitpatel/AspNetCoreOData
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <MyDataContext>(opt => opt.UseLazyLoadingProxies().UseInMemoryDatabase("MyDataContextList"));

            IEdmModel model0 = EdmModelBuilder.GetEdmModel();
            IEdmModel model1 = EdmModelBuilder.GetEdmModelV1();
            IEdmModel model2 = EdmModelBuilder.GetEdmModelV2();

            services.AddControllers(options => {
                //{
                //    options.Conventions.Add(new MetadataApplicationModelConventionAttribute());
                //    options.Conventions.Add(new MetadataActionModelConvention());
            });

            /*services.AddConvention<MyConvention>();
             *
             * services.AddOData()
             *  .AddODataRouting(options => options
             *      .AddModel(EdmModelBuilder.GetEdmModel())
             *      .AddModel("v1", EdmModelBuilder.GetEdmModelV1())
             *      .AddModel("v2{data}", EdmModelBuilder.GetEdmModelV2()));
             *
             * services.AddODataFormatter();
             * services.AddODataQuery(options => options.Count().Filter().Expand().Select().OrderBy().SetMaxTop(5));
             */

            services.AddOData(opt => opt.Count().Filter().Expand().Select().OrderBy().SetMaxTop(5)
                              .AddModel(model0)
                              .AddModel("v1", model1)
                              .AddModel("v2{data}", model2, builder => builder.AddService <ODataBatchHandler, DefaultODataBatchHandler>(Microsoft.OData.ServiceLifetime.Singleton))
                              );
        }
コード例 #12
0
        static TestModel()
        {
            BoundedContextElement context = BoundedContextElement.Config
                                            .Name("Context")
                                            .ConceptualModel(
                StructuralModelElement.Config
                .Types((EnumTypeElement)EnumTypeElement.Config.Name("EnumType").Member("Member1", 0).Member("Member2", 1))
                .Elements(
                    EntityElement.Config
                    .Name("MasterClass")
                    .HasKey("Id")
                    .Property(EntityPropertyElement.Config.Name("Id").OfType(ElementaryTypeKind.Int32))
                    .Property(EntityPropertyElement.Config.Name("Name").OfType(ElementaryTypeKind.String))
                    .Property(EntityPropertyElement.Config.Name("EnumType").OfType <EnumTypeElement>(EnumTypeElement.Config.Name("EnumType")))
                    .Relation(EntityRelationElement.Config
                              .Name("NestedClass")
                              .DirectTo(
                                  EntityElement.Config
                                  .Name("NestedClass")
                                  .HasKey("Id")
                                  .Property(EntityPropertyElement.Config.Name("Id").OfType(ElementaryTypeKind.Int32))
                                  .Property(EntityPropertyElement.Config.Name("Name").OfType(ElementaryTypeKind.String))
                                  )
                              .AsOne())
                    ));

            var provider  = CreateProvider(MockSource(context));
            var contextId = context.Identity.Id;

            var edmModelBuilder = new EdmModelBuilder(provider);

            EdmModel = edmModelBuilder.Build(contextId).AnnotateByClrTypes(ClrTypes);
        }
コード例 #13
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <SecurityDbContext>(opt => opt.UseInMemoryDatabase("Example"));

            services.AddScoped <IAccountRepository, AccountRepository>();
            services.AddScoped <IUserRepository, UserRepository>();

            services.AddHostedService <DataSeedService>();
            services.AddSingleton <IMapper, Mapper>();

            services.AddOData(opts => opts
                              .Count()
                              .Filter()
                              .Expand()
                              .Select()
                              .OrderBy()
                              .SetMaxTop(null)
                              .AddModel("v{version}", EdmModelBuilder.GetEdmModel()));

            services
            .AddAuthentication("Bearer")
            .AddScheme <AuthenticationSchemeOptions, FakeAuthenticationHandler>("Bearer", null);

            services.AddControllers();

            services.AddApiVersioning(opts =>
            {
                opts.ReportApiVersions = true;
            });
        }
コード例 #14
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseOptions();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            // Faccio la mia bella hotfix!
            app.UseCors(opt => opt
                        .WithOrigins("http://localhost:4200", "http://localhost")
                        .AllowAnyHeader()
                        .AllowAnyMethod()
                        .AllowCredentials());

            app.UseMvc(routeBuilder =>
            {
                routeBuilder.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");

                // Enable full OData queries, you might want to consider which would be actually enabled in production scenaries
                routeBuilder.Count().Filter().OrderBy().Expand().Select().MaxTop(null);

                routeBuilder.MapODataServiceRoute("ODataRoute", "odata", EdmModelBuilder.CreateModel());
            });
        }
コード例 #15
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            IEdmModel model = EdmModelBuilder.GetEdmModel();

            // Please add "UseODataBatching()" before "UseRouting()" to support OData $batch.
            app.UseODataBatching();

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapODataRoute(
                    "nullPrefix", null,
                    b =>
                {
                    b.AddService(Microsoft.OData.ServiceLifetime.Singleton, sp => model);
                    b.AddService <ODataDeserializerProvider>(Microsoft.OData.ServiceLifetime.Singleton, sp => new EntityReferenceODataDeserializerProvider(sp));
                    b.AddService <IEnumerable <IODataRoutingConvention> >(Microsoft.OData.ServiceLifetime.Singleton,
                                                                          sp => ODataRoutingConventions.CreateDefaultWithAttributeRouting("nullPrefix", endpoints.ServiceProvider));
                });

                endpoints.MapODataRoute("odataPrefix", "odata", model);

                endpoints.MapODataRoute("myPrefix", "my/{data}", model);

                endpoints.MapODataRoute("msPrefix", "ms", model, new DefaultODataBatchHandler());
            });
        }
コード例 #16
0
        /// <summary>
        /// Gets The model to use for the specified test configuration.
        /// </summary>
        /// <param name="testConfiguration">The test configuration to use.</param>
        /// <returns>The model to use for the test.</returns>
        protected override IEdmModel GetMetadataProvider(ReaderTestConfiguration testConfiguration)
        {
            IEdmModel model = base.GetMetadataProvider(testConfiguration);

            if (model == null)
            {
                // Try to set the cached model if it is null. If the PayloadEdmModel is null cached model will stay null.
                if (this.cachedModel == null)
                {
                    this.cachedModel = this.PayloadEdmModel;
                }

                if (this.cachedModel != null)
                {
                    if (this.Annotations != null)
                    {
                        this.cachedModel = EdmModelBuilder.BuildAnnotationModel(this.Annotations, this.cachedModel);
                    }
                }

                model = this.cachedModel;
            }

            return(model);
        }
コード例 #17
0
ファイル: ContentQueryService.cs プロジェクト: neoayi/squidex
        public ContentQueryService(
            IAppProvider appProvider,
            IAssetUrlGenerator assetUrlGenerator,
            IContentRepository contentRepository,
            IContentVersionLoader contentVersionLoader,
            IScriptEngine scriptEngine,
            IOptions <ContentOptions> options,
            EdmModelBuilder modelBuilder)
        {
            Guard.NotNull(appProvider, nameof(appProvider));
            Guard.NotNull(assetUrlGenerator, nameof(assetUrlGenerator));
            Guard.NotNull(contentRepository, nameof(contentRepository));
            Guard.NotNull(contentVersionLoader, nameof(contentVersionLoader));
            Guard.NotNull(modelBuilder, nameof(modelBuilder));
            Guard.NotNull(options, nameof(options));
            Guard.NotNull(scriptEngine, nameof(scriptEngine));

            this.appProvider          = appProvider;
            this.assetUrlGenerator    = assetUrlGenerator;
            this.contentRepository    = contentRepository;
            this.contentVersionLoader = contentVersionLoader;
            this.modelBuilder         = modelBuilder;
            this.options      = options.Value;
            this.scriptEngine = scriptEngine;
        }
コード例 #18
0
 public SelectExpandBinderTests()
 {
     _model       = EdmModelBuilder.GetEdmModel();
     _customer    = _model.SchemaElements.OfType <IEdmEntityType>().First(c => c.Name == "Customer");
     _vipCustomer = _model.SchemaElements.OfType <IEdmEntityType>().First(c => c.Name == "VipCustomer");
     _address     = _model.SchemaElements.OfType <IEdmComplexType>().First(c => c.Name == "Address");
     _customers   = _model.EntityContainer.FindEntitySet("Customers");
 }
コード例 #19
0
        private static HttpClient GetClient()
        {
            var config = new HttpConfiguration();

            config.MapODataServiceRoute("odata", "odata", EdmModelBuilder.GetEdmModel());

            return(new HttpClient(new HttpServer(config)));
        }
コード例 #20
0
        private static IEdmModel BuildModel(IMetadataProvider provider, Uri contextId)
        {
            var builder = new EdmModelBuilder(provider);
            var model   = builder.Build(contextId);

            model.Dump();

            return(model);
        }
コード例 #21
0
        private static IEdmModel BuildModel(Uri contextId)
        {
            var builder = new EdmModelBuilder(TestMetadataProvider.Instance, new NullEdmModelAnnotator());
            var model   = builder.Build()[contextId];

            model.Dump();

            return(model);
        }
コード例 #22
0
ファイル: Startup.cs プロジェクト: droyad/OData.WebApi
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMvc(builder => builder.MapODataServiceRoute("odata", "odata", EdmModelBuilder.GetEdmModel()));
        }
コード例 #23
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <BookStoreContext>(opt => opt.UseInMemoryDatabase("BookLists"));
            services.AddDbContext <CustomerOrderContext>(opt => opt.UseInMemoryDatabase("CustomersLists"));

            services.AddControllers();
            services.AddOData(opt => opt.AddModel("odata", EdmModelBuilder.BuildBookModel()).
                              AddModel("v{version}", EdmModelBuilder.BuildCustomerModel()).Count() /*.EnableAttributeRouting = false*/);
        }
コード例 #24
0
        private static IEdmModel BuildModel(IMetadataProvider provider, Uri contextId)
        {
            var builder = new EdmModelBuilder(provider, new EdmModelAnnotator(Enumerable.Empty <Type>()));
            var model   = builder.Build()[contextId];

            model.Dump();

            return(model);
        }
コード例 #25
0
        private static HttpClient GetCaseInsensitiveClient()
        {
            var config = new HttpConfiguration();

            config.EnableCaseInsensitive(true);
            config.EnableEnumPrefixFree(true);
            config.MapODataServiceRoute("odata3", "v3", EdmModelBuilder.GetEdmModel());
            return(new HttpClient(new HttpServer(config)));
        }
コード例 #26
0
ファイル: Startup.cs プロジェクト: strandman/WebApiSample
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseOData(EdmModelBuilder.GetEdmModel());
        }
コード例 #27
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            string connectionString = @"Data Source=(LocalDb)\MSSQLLocalDB;Integrated Security=True;Initial Catalog=FilterDbContextTest";

            services.AddDbContext <FilterDbContext>(opt => opt.UseLazyLoadingProxies().UseSqlServer(connectionString));

            services.AddControllers()
            .AddOData(opt => opt.AddRouteComponents("odata", EdmModelBuilder.GetEdmModel()).EnableQueryFeatures());
        }
コード例 #28
0
        public MongoContentRepository(IMongoDatabase database, ISchemaProvider schemas, EdmModelBuilder modelBuilder)
        {
            Guard.NotNull(database, nameof(database));
            Guard.NotNull(modelBuilder, nameof(modelBuilder));
            Guard.NotNull(schemas, nameof(schemas));

            this.schemas      = schemas;
            this.database     = database;
            this.modelBuilder = modelBuilder;
        }
コード例 #29
0
        public ODataQueryTests()
        {
            var builder = new EdmModelBuilder(new MemoryCache(Options.Create(new MemoryCacheOptions())));

            var schemaEntity = new Mock <ISchemaEntityWithSchema>();

            schemaEntity.Setup(x => x.Id).Returns(Guid.NewGuid());
            schemaEntity.Setup(x => x.Version).Returns(3);
            schemaEntity.Setup(x => x.Schema).Returns(schema);

            edmModel = builder.BuildEdmModel(schemaEntity.Object, languages);
        }
コード例 #30
0
ファイル: Startup.cs プロジェクト: gathogojr/AspNetCoreOData
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            #region Codes for backup and use to compare with preview design/implementation
            //services.AddControllers(options => {
            //{
            //    options.Conventions.Add(new MetadataApplicationModelConventionAttribute());
            //    options.Conventions.Add(new MetadataActionModelConvention());
            //});

            /*services.AddConvention<MyConvention>();
             *
             * services.AddOData()
             *  .AddODataRouting(options => options
             *      .AddModel(EdmModelBuilder.GetEdmModel())
             *      .AddModel("v1", EdmModelBuilder.GetEdmModelV1())
             *      .AddModel("v2{data}", EdmModelBuilder.GetEdmModelV2()));
             *
             * services.AddODataFormatter();
             * services.AddODataQuery(options => options.Count().Filter().Expand().Select().OrderBy().SetMaxTop(5));
             */
            #endregion

            services.AddDbContext <MyDataContext>(opt => opt.UseLazyLoadingProxies().UseInMemoryDatabase("MyDataContextList"));

            IEdmModel model0 = EdmModelBuilder.GetEdmModel();
            IEdmModel model1 = EdmModelBuilder.GetEdmModelV1();
            IEdmModel model2 = EdmModelBuilder.GetEdmModelV2();
            IEdmModel model3 = EdmModelBuilder.GetEdmModelV3();

            services.AddControllers()

            /*  If you want to remove $metadata endpoint, you can use ControllerFeatureProvider as follows
             * .ConfigureApplicationPartManager(manager =>
             * {
             *  manager.FeatureProviders.Remove(manager.FeatureProviders.OfType<ControllerFeatureProvider>().FirstOrDefault());
             *  manager.FeatureProviders.Add(new RemoveMetadataControllerFeatureProvider());
             * })
             *
             * or, remove MetadataRoutingConvention in AddOData as
             *   opt.Conventions.Remove(opt.Conventions.First(convention => convention is MetadataRoutingConvention));
             */
            .AddOData(opt => opt.Count().Filter().Expand().Select().OrderBy().SetMaxTop(5)
                      .AddRouteComponents(model0)
                      .AddRouteComponents("v1", model1)
                      .AddRouteComponents("v2{data}", model2, services => services.AddSingleton <ODataBatchHandler, DefaultODataBatchHandler>())
                      .AddRouteComponents("v3", model3)
                      .Conventions.Add(new MyConvention())
                      );

            services.AddSwaggerGen();
        }
コード例 #31
0
        public ODataQueryTests()
        {
            schemaDef.Update(new SchemaProperties {
                Hints = "The User"
            });

            schemaDef.AddField(new StringField(1, "firstName", Partitioning.Language,
                                               new StringFieldProperties {
                Label = "FirstName", IsRequired = true, AllowedValues = new[] { "1", "2" }
            }));
            schemaDef.AddField(new StringField(2, "lastName", Partitioning.Language,
                                               new StringFieldProperties {
                Hints = "Last Name", Editor = StringFieldEditor.Input
            }));

            schemaDef.AddField(new BooleanField(3, "isAdmin", Partitioning.Invariant,
                                                new BooleanFieldProperties()));

            schemaDef.AddField(new NumberField(4, "age", Partitioning.Invariant,
                                               new NumberFieldProperties {
                MinValue = 1, MaxValue = 10
            }));

            schemaDef.AddField(new DateTimeField(5, "birthday", Partitioning.Invariant,
                                                 new DateTimeFieldProperties()));

            schemaDef.AddField(new AssetsField(6, "pictures", Partitioning.Invariant,
                                               new AssetsFieldProperties()));

            schemaDef.AddField(new ReferencesField(7, "friends", Partitioning.Invariant,
                                                   new ReferencesFieldProperties()));

            schemaDef.AddField(new StringField(8, "dashed-field", Partitioning.Invariant,
                                               new StringFieldProperties()));

            var builder = new EdmModelBuilder(new MemoryCache(Options.Create(new MemoryCacheOptions())));

            var schema = A.Dummy <ISchemaEntity>();

            A.CallTo(() => schema.Id).Returns(Guid.NewGuid());
            A.CallTo(() => schema.Version).Returns(3);
            A.CallTo(() => schema.SchemaDef).Returns(schemaDef);

            var app = A.Dummy <IAppEntity>();

            A.CallTo(() => app.Id).Returns(Guid.NewGuid());
            A.CallTo(() => app.Version).Returns(3);
            A.CallTo(() => app.PartitionResolver).Returns(languagesConfig.ToResolver());

            edmModel = builder.BuildEdmModel(schema, app);
        }
コード例 #32
0
        private static IEdmModel BuildModel(IMetadataProvider provider, Uri contextId)
        {
            var builder = new EdmModelBuilder(provider, new EdmModelAnnotator(Enumerable.Empty<Type>()));
            var model = builder.Build()[contextId];

            model.Dump();

            return model;
        }