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


C# ODataConventionModelBuilder.Entity方法代码示例

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


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

示例1: Register

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

            var newFormater = new CsvTextMediaFormatter();
            newFormater.MediaTypeMappings.Add(new QueryStringMapping("frmt", "fwt", new MediaTypeHeaderValue("text/plain")));
            config.Formatters.Add(newFormater);

            config.Formatters.JsonFormatter.MediaTypeMappings.Add(
            new QueryStringMapping("frmt", "json",
            new MediaTypeHeaderValue("application/json")));

            config.Formatters.XmlFormatter.MediaTypeMappings.Add(
            new QueryStringMapping("frmt", "xml",
            new MediaTypeHeaderValue("application/xml")));

            // Serialize les types complexes qui sont rattachés à l'objet
            //var json = config.Formatters.JsonFormatter;
            //json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
            //config.Formatters.Remove(config.Formatters.XmlFormatter);

            // New code:
            // Odata
            ODataModelBuilder builder = new ODataConventionModelBuilder();
            builder.EntitySet<Individual>("Individuals");
            builder.EntitySet<Contract>("Contracts");
            ODataHttpRouteCollectionExtensions.MapODataRoute(config.Routes, routeName: "ODataRoute", routePrefix: "odata", model: builder.GetEdmModel());

            builder.Entity<Individual>().Ignore(item => item.Contracts);
            builder.Entity<Contract>().Ignore(item => item.Individual);
        }
开发者ID:Redenil,项目名称:RDAcademy,代码行数:35,代码来源:WebApiConfig.cs

示例2: ModelBuilder

        internal static void ModelBuilder(ODataConventionModelBuilder builder)
        {
            var EntitySetName = "Jobs";

            builder.EntitySet<Job>(EntitySetName);

            builder.Entity<Job>().Action("Run").Returns<String>();
            builder.Entity<Job>().Action("Finish").Returns<String>();
        }
开发者ID:dfensgmbh,项目名称:biz.dfch.CS.Entity.LifeCycleManager,代码行数:9,代码来源:JobsController.cs

示例3: ModelBuilder

        internal static void ModelBuilder(ODataConventionModelBuilder builder)
        {
            var EntitySetName = "LifeCycles";

            builder.EntitySet<LifeCycle>(EntitySetName);

            builder.Entity<LifeCycle>().Action("Next").Returns<String>();
            builder.Entity<LifeCycle>().Action("Cancel").Returns<String>();

            builder.Entity<LifeCycle>().Action("Allow").Returns<String>();
            builder.Entity<LifeCycle>().Action("Decline").Returns<String>();
        }
开发者ID:dfensgmbh,项目名称:biz.dfch.CS.Entity.LifeCycleManager,代码行数:12,代码来源:LifeCyclesController.cs

示例4: GetModel

 private static IEdmModel GetModel()
 {
     ODataModelBuilder builder = new ODataConventionModelBuilder();
     builder.ContainerName = "Container";
     builder.Namespace = "org.odata";
     // Action with no overloads
     builder.EntitySet<Vehicle>("Vehicles").EntityType.Action("Drive");
     // Valid overloads of "Wash" bound to different entities
     builder.Entity<Motorcycle>().Action("Wash");
     builder.Entity<Car>().Action("Wash");
     // Invalid overloads of "Park"
     builder.Entity<Car>().Action("Park");
     builder.Entity<Car>().Action("Park").Parameter<string>("mood");
     return builder.GetEdmModel();
 }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:15,代码来源:ODataActionParametersTest.cs

示例5: Register

        public static void Register( HttpConfiguration config ) {
            config.EnableCors();
            config.MapHttpAttributeRoutes();
            // To prevent Error: Self referencing loop
            config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Serialize;
            config.Formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.Objects;

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

            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

            builder.EntitySet<IUser>( "Users" );
            builder.EntitySet<WebUser>( "WebUsers" );
            builder.EntitySet<Guest>( "Guests" );
            builder.EntitySet<Login>( "LoginSet" );
            builder.EntitySet<Permission>( "PermissionSet" );
            builder.EntitySet<Role>( "RoleSet" );
            builder.EntitySet<Address>( "AddressSet" );
            builder.EntitySet<Credential>( "CredentialSet" );
            builder.EntitySet<Task>( "TaskSet" );

            builder.Namespace = "OdataApi.Controllers";
            builder.Entity<WebUser>().Action( "Post" ).Parameter<int>( "Rating" );

            config.Routes.MapODataServiceRoute( "odata", "odata", builder.GetEdmModel() );
        }
开发者ID:ulrich1966,项目名称:PlayHouseSolution,代码行数:30,代码来源:WebApiConfig.cs

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

示例7: Register

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

            // OData
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.EntitySet<Customer>("Customers");
            builder.EntitySet<Invoice>("Invoices");

            // OData Action
            ActionConfiguration purchase = builder.Entity<Customer>().Action("Purchase");
            purchase.Parameter<int>("AmountOfShoes");
            purchase.ReturnsFromEntitySet<Invoice>("Invoices");

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

            // OData with fixed metadata
            // see: http://www.getbreezenow.com/documentation/odata-server
            config.Routes.MapODataServiceRoute("odataFixed", "odataFixed", EdmBuilder.GetEdm<DataContext>(), new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer));
        }
开发者ID:JohannesHoppe,项目名称:Artikel,代码行数:26,代码来源:WebApiConfig.cs

示例8: GetModel

 private static IEdmModel GetModel()
 {
     ODataModelBuilder builder = new ODataConventionModelBuilder();
     var pets = builder.EntitySet<Pet>("Pets");
     builder.Entity<BigPet>();
     return builder.GetEdmModel();
 }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:7,代码来源:MinimalMetadataSpecificTests.cs

示例9: CreateCustomerContext

 internal static ODataQueryContext CreateCustomerContext()
 {
     ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
     builder.EntitySet<QueryCompositionCustomer>("Customer");
     builder.Entity<QueryCompositionCustomerBase>();
     IEdmModel model = builder.GetEdmModel();
     return new ODataQueryContext(model, typeof(QueryCompositionCustomer));
 } 
开发者ID:naulizzang,项目名称:aspnetwebstack,代码行数:8,代码来源:ValidationTestHelper.cs

示例10: GetCustomersModel

 private static IEdmModel GetCustomersModel()
 {
     HttpConfiguration configuration = new HttpConfiguration();
     configuration.Services.Replace(typeof(IAssembliesResolver), new TestAssemblyResolver(typeof(QueryCompositionCustomer)));
     ODataConventionModelBuilder builder = new ODataConventionModelBuilder(configuration);
     builder.EntitySet<QueryCompositionCustomer>("Customer");
     builder.Entity<QueryCompositionCustomerBase>();
     return builder.GetEdmModel();
 }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:9,代码来源:ValidationTestHelper.cs

示例11: GetModel

 private static IEdmModel GetModel()
 {
     ODataModelBuilder builder = new ODataConventionModelBuilder();
     builder.EntitySet<AROCustomer>("AROCustomers");
     builder.Entity<AROVipCustomer>().DerivesFrom<AROCustomer>();
     builder.EntitySet<AROAddress>("AROAddresses");
     builder.EntitySet<AROOrder>("Orders");
     return builder.GetEdmModel();
 }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:9,代码来源:AddRelatedObjectTests.cs

示例12: ShouldIgnoreStaticProperty

        public void ShouldIgnoreStaticProperty()
        {
            ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();
            modelBuilder.Entity<ImplicitModelBuilder_EntityWithStaticProperty>();
            var model = modelBuilder.GetEdmModel();

            var actual = model.SchemaElements.Where(e => e.Name == typeof(ImplicitModelBuilder_EntityWithStaticProperty).Name).OfType<EdmEntityType>().Single();
            Assert.Equal(1, actual.Properties().Count());
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:9,代码来源:ImplicitModelBuilderTests.cs

示例13: GetModel

 private static IEdmModel GetModel()
 {
     ODataModelBuilder builder = new ODataConventionModelBuilder();
     EntitySetConfiguration<Customer> customers = builder.EntitySet<Customer>("Customers");
     EntityTypeConfiguration<VipCustomer> vipCustoemer = builder.Entity<VipCustomer>().DerivesFrom<Customer>();
     EntitySetConfiguration<Order> orders = builder.EntitySet<Order>("Orders");
     EntitySetConfiguration<Address> address = builder.EntitySet<Address>("Addresses");
     EntitySetConfiguration<PersonalInformation> information = builder.EntitySet<PersonalInformation>("Informations");
     return builder.GetEdmModel();
 }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:10,代码来源:LinksRoutingConventionTests.cs

示例14: GetEdmModel

 private static IEdmModel GetEdmModel(HttpConfiguration configuration)
 {
     ODataModelBuilder builder = new ODataConventionModelBuilder(configuration);
     EntitySetConfiguration<SingleResultCustomer> customers = builder.EntitySet<SingleResultCustomer>("SingleResultCustomers");
     EntitySetConfiguration<SingleResultOrderDetail> orderDetails = builder.EntitySet<SingleResultOrderDetail>("SingleResultOrderDetail");
     EntityTypeConfiguration<SingleResultPremiumCustomer> premiumCustomer = builder.Entity<SingleResultPremiumCustomer>();
     customers.EntityType.Action("CreditRating").Returns<double>();
     EntitySetConfiguration<SingleResultOrder> orders = builder.EntitySet<SingleResultOrder>("SingleResultOrder");
     EntitySetConfiguration<SingleResultBonus> bonuses = builder.EntitySet<SingleResultBonus>("SingleResultBonus");
     IEdmModel model = builder.GetEdmModel();
     return model;
 }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:12,代码来源:SingleResultSelectExpandTests.cs

示例15: Register

        public static void Register(HttpConfiguration config)
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.EntitySet<Product>("Products");
            builder.EntitySet<Supplier>("Suppliers");
            builder.EntitySet<ProductRating>("Ratings");
            ActionConfiguration rateProduct = builder.Entity<Product>().Action("RateProduct");
            rateProduct.Parameter<int>("Rating");
            rateProduct.Returns<double>();

            config.Routes.MapODataRoute("odata", "odata", builder.GetEdmModel());
        }
开发者ID:kensan73,项目名称:odata_ef_service_client_example,代码行数:12,代码来源:WebApiConfig.cs


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