• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Builder.ODataConventionModelBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: Application_Start

        public void Application_Start()
        {
            var edmx = new XmlDocument();
            edmx.Load(HttpContext.Current.Server.MapPath(WesentConfiguration.DefaultInstance.Model));
            var modelParser = new EdmxParser(edmx);

            var types = new RuntimeTypeGenerator(modelParser).GenerateTypes();

            GlobalConfiguration.Configure(config =>
            {

                //config.MessageHandlers.Add(new BasicAuthenticationHandler());
                //config.Filters.Add(new BasicAuthorizationFilter());

                ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

                config.Services.Replace(typeof(IHttpControllerSelector), new DynamicControllerSelector(config, types));

                foreach (var kv in types)
                {
                    var mi = typeof(ODataConventionModelBuilder).GetMethod("EntitySet").MakeGenericMethod(kv.Value); ;
                    mi.Invoke(builder, new[] { kv.Key });
                }
                config.Routes.MapODataRoute("odata", "", builder.GetEdmModel());

                if(!Directory.Exists("C:\\LogFiles\\wesent\\"))
                {
                    Directory.CreateDirectory("C:\\LogFiles\\wesent\\");
                }
                File.AppendAllLines("C:\\LogFiles\\wesent\\log.log", new[] { DateTime.Now.ToString() });

            });
        }
开发者ID:evisar,项目名称:wesent,代码行数:33,代码来源:Global.asax.cs


示例17: 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


示例18: Register

        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services

            // Web API routes
            config.MapHttpAttributeRoutes();

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

            var cors = new EnableCorsAttribute("*", "*", "*");
            config.EnableCors(cors);

            // 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();

            var modelBuilder = new ODataConventionModelBuilder();
            modelBuilder.EntitySet<Song>("Songs");
            modelBuilder.EntitySet<Artist>("Artists");
            modelBuilder.EntitySet<Album>("Albums");

            var json = config.Formatters.JsonFormatter;
            json.SerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.Objects;

            var model = modelBuilder.GetEdmModel();
            config.Routes.MapODataRoute("odata", "odata", model);
            config.EnableQuerySupport();
        }
开发者ID:jwendl,项目名称:MusicApp,代码行数:33,代码来源:WebApiConfig.cs


示例19: 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


示例20: GetEdmModel

        internal static IEdmModel GetEdmModel(this ApiActionDescriptor actionDescriptor, Type entityClrType)
        {
            if (actionDescriptor == null)
            {
                throw Error.ArgumentNull("actionDescriptor");
            }

            if (entityClrType == null)
            {
                throw Error.ArgumentNull("entityClrType");
            }

            // save the EdmModel to the action descriptor
            return actionDescriptor.Properties.GetOrAdd(EdmModelKey + entityClrType.FullName, _ =>
            {
                // It's safe to create HttpConfiguration, since it's used as an assembly Resolver.
                //ODataConventionModelBuilder builder = new ODataConventionModelBuilder(new HttpConfiguration(), isQueryCompositionMode: true);
                ODataConventionModelBuilder builder = new ODataConventionModelBuilder(new HttpConfiguration());
                EntityTypeConfiguration entityTypeConfiguration = builder.AddEntity(entityClrType);
                builder.AddEntitySet(entityClrType.Name, entityTypeConfiguration);
                IEdmModel edmModel = builder.GetEdmModel();
                Contract.Assert(edmModel != null);
                return edmModel;
            }) as IEdmModel;
        }
开发者ID:dax70,项目名称:MvcApi,代码行数:25,代码来源:ActionDescriptorExtensions.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Deserialization.ODataDeserializerContext类代码示例发布时间:2022-05-26
下一篇:
C# OData.Delta类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap