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


C# ODataConventionModelBuilder.GetEdmModel方法代码示例

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


在下文中一共展示了ODataConventionModelBuilder.GetEdmModel方法的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)
        {
            // Dependency resolver for dependency injection
            UnityContainer container = new UnityContainer();
            container.RegisterType<IResearchRepository, ResearchRepository>(new HierarchicalLifetimeManager());
            container.RegisterType<IProjectsRepository, ProjectsRepository>(new HierarchicalLifetimeManager());
            container.RegisterType<IReferencesRepository, ReferencesRepository>(new HierarchicalLifetimeManager());
            config.DependencyResolver = new UnityResolver(container);

            config.MapHttpAttributeRoutes();

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

            //OData Models
            ODataModelBuilder odataBuilder = new ODataConventionModelBuilder();
            odataBuilder.Namespace = "SpResearchTracker.Models";
            odataBuilder.EntitySet<Project>("Projects");
            odataBuilder.EntitySet<Reference>("References");

            // OData routes
            config.Routes.MapODataRoute(
              routeName: "odata",
              routePrefix: "odata",
              model: odataBuilder.GetEdmModel(),
              batchHandler: new BreezeODataBatchHandler(GlobalConfiguration.DefaultServer));
        }
开发者ID:ruperthulme,项目名称:Research-Project-Code-Sample,代码行数:30,代码来源:WebApiConfig.cs

示例5: Register

        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            GlobalConfiguration.Configuration.Formatters.Clear();
            var formatter = new JsonMediaTypeFormatter
                                {
                                    SerializerSettings =
                                        new JsonSerializerSettings
                                            {
                                                PreserveReferencesHandling =
                                                    PreserveReferencesHandling.Objects
                                            }
                                };

            GlobalConfiguration.Configuration.Formatters.Add(formatter);

            // OData
            var builder = new ODataConventionModelBuilder();
            builder.EntitySet<UserDevice>("UserDevice");
            builder.EntitySet<UserInformation>("UserInformation");
            config.Routes.MapODataRoute("odata", "odata", builder.GetEdmModel());

            // Web API routes
            config.MapHttpAttributeRoutes();

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

示例6: Register

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

            // Attribute routing.
            config.MapHttpAttributeRoutes();

            // Validate all models sent to server upon receiving them
            config.Filters.Add(new ValidateModelAttribute(false));

            // There must be exactly one exception handler. (There is a default one that may be replaced.)
            // To make this sample easier to run in a browser, replace the default exception handler with one that sends
            // back text/plain content for all errors.
            config.Services.Replace(typeof(IExceptionHandler), new SiteExceptionHandler());

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

            // OData
            var builder = new ODataConventionModelBuilder();
            builder.EntitySet<Product>("Product");
            builder.EntitySet<Category>("Category");
            config.Routes.MapODataRoute("odata", "odata", builder.GetEdmModel());

            // Custom JsonFormatter resolving
            ////config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver();
        }
开发者ID:johnsmith9264,项目名称:Mvc4Application1,代码行数:34,代码来源:WebApiConfig.cs

示例7: GetModel

 private static IEdmModel GetModel()
 {
     ODataModelBuilder builder = new ODataConventionModelBuilder();
     var customers = builder.EntitySet<PropertyCustomer>("PropertyCustomers");
     customers.EntityType.Ignore(p => p.Secret);
     return builder.GetEdmModel();
 }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:7,代码来源:PropertyTests.cs

示例8: 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));
            config.Filters.Add(new AzureRaceDataWebAPI.Filters.ValidateHttpAntiForgeryTokenAttribute());

            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.EntitySet<Meeting>("Meetings");
            builder.EntitySet<RaceStartItem>("RaceStartItem");
            builder.EntitySet<CoverageItem>("CoverageItem");

            config.Routes.MapODataRoute("odata", "odata", builder.GetEdmModel());

            //Use JSON formatting by default
            var json = config.Formatters.JsonFormatter;
            json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
            config.Formatters.Remove(config.Formatters.XmlFormatter);

            config.EnableCors();

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
开发者ID:vdmerweandre,项目名称:AzureMVCWebSiteWithOAuth,代码行数:31,代码来源: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.GetEdmModel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。