当前位置: 首页>>代码示例>>C#>>正文


C# Builder.ODataConventionModelBuilder类代码示例

本文整理汇总了C#中System.Web.Http.OData.Builder.ODataConventionModelBuilder的典型用法代码示例。如果您正苦于以下问题:C# ODataConventionModelBuilder类的具体用法?C# ODataConventionModelBuilder怎么用?C# ODataConventionModelBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ODataConventionModelBuilder类属于System.Web.Http.OData.Builder命名空间,在下文中一共展示了ODataConventionModelBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Register

        public static void Register(HttpConfiguration config)
        {
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            // 取消注释下面的代码行可对具有 IQueryable 或 IQueryable<T> 返回类型的操作启用查询支持。
            // 若要避免处理意外查询或恶意查询,请使用 QueryableAttribute 上的验证设置来验证传入查询。
            // 有关详细信息,请访问 http://go.microsoft.com/fwlink/?LinkId=279712。
            //config.EnableQuerySupport();

            // 若要在应用程序中禁用跟踪,请注释掉或删除以下代码行
            // 有关详细信息,请参阅: http://www.asp.net/web-api
            config.EnableSystemDiagnosticsTracing();

            // 参考:http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v3/creating-an-odata-endpoint
            var builder = new ODataConventionModelBuilder();
            builder.EntitySet<Product>("Products");
            // 参考:http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v3/working-with-entity-relations
            builder.EntitySet<Supplier>("Suppliers");
            //config.Routes.MapODataRoute("OData", "odata", builder.GetEdmModel());
            config.Routes.MapODataServiceRoute("ODataRoute", "odata", builder.GetEdmModel());
        }
开发者ID:SunriseSamples,项目名称:ODataTest,代码行数:25,代码来源:WebApiConfig.cs

示例2: Register

		public static void Register(HttpConfiguration config)
		{
			// Attribute routing.
			config.MapHttpAttributeRoutes();

			config.Routes.MapHttpRoute(
				name: "DefaultApi",
				routeTemplate: "v1/{controller}/{id}",
				defaults: new { id = RouteParameter.Optional }
			);

			// Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type.
			// To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries.
			// For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712.
			config.AddODataQueryFilter();

			var builder = new ODataConventionModelBuilder();
			builder.EntitySet<Repository>("Repositories");
			builder.EntitySet<Session>("Sessions");
			builder.EntitySet<LogEntry>("LogEntries");
			config.Routes.MapODataServiceRoute("odata", "odata/v1", builder.GetEdmModel());

			// To disable tracing in your application, please comment out or remove the following line of code
			// For more information, refer to: http://www.asp.net/web-api
			config.EnableSystemDiagnosticsTracing();

			// Use camel case for JSON data.
			config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
		}
开发者ID:nHook,项目名称:nH.Web,代码行数:29,代码来源:WebApiConfig.cs

示例3: GetSampleModel

 private static IEdmModel GetSampleModel()
 {
     ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
     builder.EntitySet<Employee>("employees");
     builder.EntitySet<WorkItem>("workitems");
     return builder.GetEdmModel();
 }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:7,代码来源:EntityTypeTest.cs

示例4: Register

        public static void Register(HttpConfiguration config)
        {
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            // Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type.
            // To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries.
            // For more information, visit http://go.microsoft.com/fwlink/?LinkId=301869.
            //config.EnableQuerySupport();

            ODataConventionModelBuilder modelBuilder = new ODataConventionModelBuilder();
            modelBuilder.EntitySet<Employee>("Employees");
            var model = modelBuilder.GetEdmModel();

            config.Routes.MapODataRoute(routeName: "OData", routePrefix: "odata", model: model);

            // To disable tracing in your application, please comment out or remove the following line of code
            // For more information, refer to: http://www.asp.net/web-api
            config.EnableSystemDiagnosticsTracing();
        }
开发者ID:humaNiT,项目名称:humaNiT,代码行数:25,代码来源:WebApiConfig.cs

示例5: Register

        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            // Configure Web API to use only bearer token authentication.
            config.SuppressDefaultHostAuthentication();
            config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "CustomRoute",
                routeTemplate: "api/library/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            //Newly added for OData
            //    ODataModelBuilder builder = new ODataConventionModelBuilder();
            //    builder.EntitySet<Book>("Book");
            //    config.MapODataServiceRoute(
            //        routeName: "odata",
            //        routePrefix: "odata",
            //        model: builder.GetEdmModel());
            //}

            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.EntitySet<Book>("Book");
            config.Routes.MapODataServiceRoute("odata", "odata", builder.GetEdmModel());
        }
开发者ID:mahedee,项目名称:WebAPICookBook,代码行数:35,代码来源:WebApiConfig.cs

示例6: GetEdmModel

        public static IEdmModel GetEdmModel()
        {
            var builder = new ODataConventionModelBuilder();

            builder.DataServiceVersion = new Version(2, 0);
            builder.MaxDataServiceVersion = new Version(2, 0);
            builder.Namespace = "NuGetGallery";
            builder.ContainerName = "V2FeedContext";

            var packagesCollection = builder.EntitySet<V2FeedPackage>("Packages");
            packagesCollection.EntityType.HasKey(pkg => pkg.Id);
            packagesCollection.EntityType.HasKey(pkg => pkg.Version);

            var searchAction = builder.Action("Search");
            searchAction.Parameter<string>("searchTerm");
            searchAction.Parameter<string>("targetFramework");
            searchAction.Parameter<bool>("includePrerelease");
            searchAction.ReturnsCollectionFromEntitySet<V2FeedPackage>("Packages");

            var findPackagesAction = builder.Action("FindPackagesById");
            findPackagesAction.Parameter<string>("id");
            findPackagesAction.ReturnsCollectionFromEntitySet<V2FeedPackage>("Packages");

            var model = builder.GetEdmModel();
            model.SetEdmVersion(new Version(1, 0));
            model.SetEdmxVersion(new Version(1, 0));
            model.SetHasDefaultStream(model.FindDeclaredType(typeof(V2FeedPackage).FullName) as IEdmEntityType, hasStream: true);

            return model;
        }
开发者ID:ZhiYuanHuang,项目名称:NuGetGallery,代码行数:30,代码来源:NuGetODataV2CuratedFeedConfig.cs

示例7: GetInheritanceModel

 private static IEdmModel GetInheritanceModel(HttpConfiguration config)
 {
     ODataModelBuilder builder = new ODataConventionModelBuilder(config);
     var baseEntitySet = builder.EntitySet<BaseEntity>("BaseEntity");
     var derivedEntityType = builder.Entity<DerivedEntity>().DerivesFrom<BaseEntity>();
     return builder.GetEdmModel();
 }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:7,代码来源:EntryMetadataTests.cs

示例8: GetModel

 static IEdmModel GetModel()
 {
     ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
     builder.EntitySet<TodoList>("TodoLists");
     builder.EntitySet<TodoItem>("Todos");
     return builder.GetEdmModel();
 }
开发者ID:andreychizhov,项目名称:microsoft-aspnet-samples,代码行数:7,代码来源:WebApiConfig.cs

示例9: Configuration

        // Invoked once at startup to configure your application.
        public void Configuration(IAppBuilder builder)
        {
			builder.Use((context, next) => { context.Response.Headers.Add("MyHeader", new [] { "abc" }); return next(); });

			builder.UseStaticFiles("/Client");
			//builder.UseFileServer(new FileServerOptions()
			//{
			//	RequestPath = new PathString("/Client"),
			//	FileSystem = new PhysicalFileSystem(".\\Client")
			//});

			builder.Use<BasicAuthentication>();

			HttpConfiguration config = new HttpConfiguration();
			config.Routes.MapHttpRoute("Default", "api/Customer/{customerID}", new { controller="CustomerWebApi", customerID = RouteParameter.Optional });

			var oDataBuilder = new ODataConventionModelBuilder();
			oDataBuilder.EntitySet<Customer>("Customer");
			config.Routes.MapODataRoute("odata", "odata", oDataBuilder.GetEdmModel());

			// Use this if you want XML instead of JSON
			//config.Formatters.XmlFormatter.UseXmlSerializer = true;
			//config.Formatters.Remove(config.Formatters.JsonFormatter);

            config.Formatters.JsonFormatter.UseDataContractJsonSerializer = true;
			//config.Formatters.Remove(config.Formatters.XmlFormatter);

            builder.UseWebApi(config);
		}
开发者ID:mkandroid15,项目名称:Samples,代码行数:30,代码来源:Startup.cs

示例10: Register

        public static void Register(HttpConfiguration config)
        {
            //config.Routes.MapHttpRoute(
            //    name: "DefaultApi",
            //    routeTemplate: "api/{controller}/{id}",
            //    defaults: new { id = RouteParameter.Optional }
            //);

            // Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type.
            // To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries.
            // For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712.
            //config.EnableQuerySupport();

            // To disable tracing in your application, please comment out or remove the following line of code
            // For more information, refer to: http://www.asp.net/web-api
            //config.EnableSystemDiagnosticsTracing();

            ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();
            modelBuilder.EntitySet<QueueModel>("Queues");
            modelBuilder.EntitySet<QueueDetailModel>("QueueDetails");
            //modelBuilder.EntitySet<TestModel>("Test");
            modelBuilder.EntitySet<CaseModel>("Cases");
            modelBuilder.EntitySet<CaseSummaryModel>("CasesSummary");
            modelBuilder.EntitySet<CaseNotesModel>("CasesNotes");
            modelBuilder.EntitySet<IssueWIModel>("IssueWI");
            modelBuilder.EntitySet<QueueActivityModel>("QueueActivity");
            modelBuilder.EntitySet<EmployeeDetailModel>("EmployeeDetails");

            Microsoft.Data.Edm.IEdmModel model = modelBuilder.GetEdmModel();
            config.Routes.MapODataRoute("OdataRoute", "hapi", model);
            config.EnableQuerySupport();
        }
开发者ID:joehosemann,项目名称:hapi,代码行数:32,代码来源:WebApiConfig.cs

示例11: Register

        public static void Register(HttpConfiguration config)
        {
            // Web API routes
            config.MapHttpAttributeRoutes();

            // Use camel case for JSON data.
            config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            config.Formatters.JsonFormatter.SerializerSettings.DateFormatString = "yyyy-MM-ddTHH:mm:ssZ";
            config.Formatters.Remove(config.Formatters.XmlFormatter);

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            config.Filters.Add(new AuthorizeAttribute());
            config.Filters.Add(new SecurityExceptionFilterAttribute());

            ODataModelBuilder builder = new ODataConventionModelBuilder();
            builder.EntitySet<GroupViewModel>("Groups");
            builder.EntitySet<LessonViewModel>("Lessons");
            builder.EntitySet<ScoreViewModel>("Scores");
            builder.EntitySet<UserViewModel>("UserView");
            config.Routes.MapODataServiceRoute("odata", "odata", builder.GetEdmModel());
        }
开发者ID:WadeOne,项目名称:EasyTeach,代码行数:26,代码来源:WebApiConfig.cs

示例12: Register

        public static void Register(HttpConfiguration config)
        {
            // OData configuration
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.EntitySet<Author>("authors");
            builder.EntitySet<Blog>("blogs");
            builder.EntitySet<Comment>("comments");
            builder.EntitySet<Post>("posts");
            builder.ContainerName = "BlogItDataService";

            config.Routes.MapODataServiceRoute("OData", "api/odata", builder.GetEdmModel());

            var queryAttributes = new EnableQueryAttribute()
            {
                PageSize = 100,
                MaxTop = 100,
                EnsureStableOrdering = false
            };
            config.AddODataQueryFilter(queryAttributes);

            // Web API attribute routing
            config.MapHttpAttributeRoutes();

            // Additional formatters
            config.Formatters.Add(new BsonMediaTypeFormatter());
        }
开发者ID:jdwittenauer,项目名称:blogit,代码行数:26,代码来源:WebApiConfig.cs

示例13: GetModel

 private static IEdmModel GetModel()
 {
     ODataModelBuilder builder = new ODataConventionModelBuilder();
     EntitySetConfiguration<OrderByCustomer> customers = builder.EntitySet<OrderByCustomer>("OrderByCustomers");
     EntitySetConfiguration<OrderByOrder> orders = builder.EntitySet<OrderByOrder>("OrderByOrders");
     return builder.GetEdmModel();
 }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:7,代码来源:OrderByTests.cs

示例14: GetEdmModel

 protected static IEdmModel GetEdmModel(HttpConfiguration config)
 {
     ODataModelBuilder builder = new ODataConventionModelBuilder(config);
     var entitySet = builder.EntitySet<StubEntity>("StubEntity");
     entitySet.EntityType.Collection.Action("Paged").ReturnsCollectionFromEntitySet<StubEntity>("StubEntity");
     return builder.GetEdmModel();
 }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:7,代码来源:FeedMetadataTests.cs

示例15: Register

        public static void Register( HttpConfiguration config )
        {
            XmlConfigurator.Configure();
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.EntitySet<WebUser>( "WebUsers" );
            builder.EntitySet<Login>( "Logins" );
            builder.EntitySet<Role>( "Roles" );
            builder.EntitySet<Address>( "Address" );
            builder.EntitySet<Permission>( "Permissions" );
            builder.EntitySet<Credential>( "Credentials" );
            builder.EntitySet<Task>( "Tasks" );
            builder.EntitySet<IUser>( "IUsers" );

            var conventions = ODataRoutingConventions.CreateDefault();
            conventions.Insert( 0, new NavigationIndexRoutingConvention() );
            config.Routes.MapODataServiceRoute( "odata", "odata", builder.GetEdmModel(), new DefaultODataPathHandler(), conventions );

            // Obsolet:
            //config.Routes.MapODataRoute( routeName: "OData", routePrefix: "odata", model: builder.GetEdmModel() );

            //  config.Routes.MapHttpRoute(
            //    name: "DefaultApi",
            //    routeTemplate: "odata/{controller}/{id}",
            //    defaults: new { id = RouteParameter.Optional }
            //);
        }
开发者ID:ulrich1966,项目名称:PlayHouse,代码行数:26,代码来源:WebApiConfig.cs


注:本文中的System.Web.Http.OData.Builder.ODataConventionModelBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。