public void CanCreateEdmModel_WithNonBindableAction() { // Arrange ODataModelBuilder builder = ODataModelBuilderMocks.GetModelBuilderMock <ODataModelBuilder>(); // Act ActionConfiguration actionConfiguration = builder.Action("ActionName"); actionConfiguration.ReturnsFromEntitySet <Customer>("Customers"); IEdmModel model = builder.GetEdmModel(); // Assert IEdmEntityContainer container = model.EntityContainer; Assert.NotNull(container); Assert.Single(container.Elements.OfType <IEdmActionImport>()); Assert.Single(container.Elements.OfType <IEdmEntitySet>()); IEdmActionImport action = container.Elements.OfType <IEdmActionImport>().Single(); Assert.False(action.Action.IsBound); Assert.Equal("ActionName", action.Name); Assert.NotNull(action.Action.ReturnType); Assert.NotNull(action.EntitySet); Assert.Equal("Customers", (action.EntitySet as IEdmPathExpression).Path); Assert.Empty(action.Action.Parameters); }
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)); }
public static IEdmModel GetEdmModel() { ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); EntityTypeConfiguration <Customer> customer = builder.EntitySet <Customer>("Customers").EntityType; EntityTypeConfiguration <Order> order = builder.EntitySet <Order>("Orders").EntityType; // Add unbound function for get special customer. FunctionConfiguration getCustomersWithNameContaining = builder.Function("GetCustomersWithNameContaining"); getCustomersWithNameContaining.Parameter <string>("ContainedString"); getCustomersWithNameContaining.ReturnsCollectionFromEntitySet <Customer>("Customers"); // Add bound action for updating order price. ActionConfiguration updateOrderPrice = order.Action("UpdateOrderPrice"); updateOrderPrice.Parameter <string>("Price"); updateOrderPrice.ReturnsFromEntitySet <Order>("Orders"); // Add bound function for delete order from customer and return the rest orders. FunctionConfiguration deleteOrderFromCustomer = customer.Function("DeleteOrderFromCustomer"); deleteOrderFromCustomer.Parameter <int>("OrderId"); deleteOrderFromCustomer.ReturnsCollectionFromEntitySet <Order>("Orders"); return(builder.GetEdmModel()); }
private IEdmModel GetEdmModel() { ODataModelBuilder builder = new ODataConventionModelBuilder(); EntitySetConfiguration <Employee> employees = builder.EntitySet <Employee>("Employees"); EntitySetConfiguration <Department> departments = builder.EntitySet <Department>("Departments"); EntitySetConfiguration <Party> parties = builder.EntitySet <Party>("Parties"); EntitySetConfiguration <ObjectPermission> objectPermissions = builder.EntitySet <ObjectPermission>("ObjectPermissions"); EntitySetConfiguration <MemberPermission> memberPermissions = builder.EntitySet <MemberPermission>("MemberPermissions"); EntitySetConfiguration <TypePermission> typePermissions = builder.EntitySet <TypePermission>("TypePermissions"); employees.EntityType.HasKey(t => t.Oid); departments.EntityType.HasKey(t => t.Oid); parties.EntityType.HasKey(t => t.Oid); ActionConfiguration login = builder.Action("Login"); login.Parameter <string>("userName"); login.Parameter <string>("password"); builder.Action("Logout"); ActionConfiguration getPermissions = builder.Action("GetPermissions"); getPermissions.Parameter <string>("typeName"); getPermissions.CollectionParameter <string>("keys"); ActionConfiguration getTypePermissions = builder.Action("GetTypePermissions"); getTypePermissions.Parameter <string>("typeName"); getTypePermissions.ReturnsFromEntitySet <TypePermission>("TypePermissions"); return(builder.GetEdmModel()); }
public static IEdmModel GetModel() { HttpConfiguration configuration = new HttpConfiguration(); configuration.Services.Replace(typeof(IAssembliesResolver), new TestAssemblyResolver()); ODataConventionModelBuilder builder = new ODataConventionModelBuilder(configuration); builder.EntitySet <RoutingCustomer>("RoutingCustomers"); builder.EntitySet <Product>("Products"); builder.EntitySet <SalesPerson>("SalesPeople"); builder.EntitySet <EmailAddress>("EmailAddresses"); builder.EntitySet <üCategory>("üCategories"); ActionConfiguration getRoutingCustomerById = builder.Action("GetRoutingCustomerById"); getRoutingCustomerById.Parameter <int>("RoutingCustomerId"); getRoutingCustomerById.ReturnsFromEntitySet <RoutingCustomer>("RoutingCustomers"); ActionConfiguration getSalesPersonById = builder.Action("GetSalesPersonById"); getSalesPersonById.Parameter <int>("salesPersonId"); getSalesPersonById.ReturnsFromEntitySet <SalesPerson>("SalesPeople"); ActionConfiguration getAllVIPs = builder.Action("GetAllVIPs"); ActionReturnsCollectionFromEntitySet <VIP>(builder, getAllVIPs, "RoutingCustomers"); builder.Entity <RoutingCustomer>().ComplexProperty <Address>(c => c.Address); builder.Entity <RoutingCustomer>().Action("GetRelatedRoutingCustomers").ReturnsCollectionFromEntitySet <RoutingCustomer>("RoutingCustomers"); ActionConfiguration getBestRelatedRoutingCustomer = builder.Entity <RoutingCustomer>().Action("GetBestRelatedRoutingCustomer"); ActionReturnsFromEntitySet <VIP>(builder, getBestRelatedRoutingCustomer, "RoutingCustomers"); ActionConfiguration getVIPS = builder.Entity <RoutingCustomer>().Collection.Action("GetVIPs"); ActionReturnsCollectionFromEntitySet <VIP>(builder, getVIPS, "RoutingCustomers"); builder.Entity <RoutingCustomer>().Collection.Action("GetProducts").ReturnsCollectionFromEntitySet <Product>("Products"); builder.Entity <VIP>().Action("GetSalesPerson").ReturnsFromEntitySet <SalesPerson>("SalesPeople"); builder.Entity <VIP>().Collection.Action("GetSalesPeople").ReturnsCollectionFromEntitySet <SalesPerson>("SalesPeople"); ActionConfiguration getMostProfitable = builder.Entity <VIP>().Collection.Action("GetMostProfitable"); ActionReturnsFromEntitySet <VIP>(builder, getMostProfitable, "RoutingCustomers"); ActionConfiguration getVIPRoutingCustomers = builder.Entity <SalesPerson>().Action("GetVIPRoutingCustomers"); ActionReturnsCollectionFromEntitySet <VIP>(builder, getVIPRoutingCustomers, "RoutingCustomers"); ActionConfiguration getVIPRoutingCustomersOnCollection = builder.Entity <SalesPerson>().Collection.Action("GetVIPRoutingCustomers"); ActionReturnsCollectionFromEntitySet <VIP>(builder, getVIPRoutingCustomersOnCollection, "RoutingCustomers"); builder.Entity <VIP>().HasRequired(v => v.RelationshipManager); builder.Entity <ImportantProduct>().HasRequired(ip => ip.LeadSalesPerson); return(builder.GetEdmModel()); }
private IEdmModel GetEdmModel(ODataConventionModelBuilder builder) { builder.EntitySet <ConventionCustomer>("ConventionCustomers"); builder.EntitySet <ConventionOrder>("ConventionOrders"); builder.ComplexType <ConventionPerson>(); builder.EntityType <ConventionCustomer>().ComplexProperty <ConventionAddress>(c => c.Address); // Top level action import ActionConfiguration createConventionCustomerById = builder.Action("CreateConventionCustomerById"); createConventionCustomerById.Parameter <int>("ID"); createConventionCustomerById.ReturnsFromEntitySet <ConventionCustomer>("ConventionCustomers"); // Top level action import without parameter and with a collection of primitive return type ActionConfiguration topCollectionPrimitiveAction = builder.Action("CreateCollectionMessages"); topCollectionPrimitiveAction.ReturnsCollection <string>(); // Top level function import FunctionConfiguration getAllCustomers = builder.Function("GetAllConventionCustomers"); getAllCustomers.ReturnsCollectionFromEntitySet <ConventionCustomer>("ConventionCustomers"); // Top level function import with one parameter FunctionConfiguration getCustomersById = builder.Function("GetConventionCustomerById"); getCustomersById.IsComposable = true; getCustomersById.Parameter <int>("CustomerId"); getCustomersById.ReturnsFromEntitySet <ConventionCustomer>("ConventionCustomers"); // Top level function import with two parameters FunctionConfiguration getOrder = builder.Function("GetConventionOrderByCustomerIdAndOrderName"); getOrder.Parameter <int>("CustomerId"); getOrder.Parameter <string>("OrderName"); getOrder.ReturnsFromEntitySet <ConventionOrder>("ConventionOrders"); // Top level function import with complex parameter FunctionConfiguration complexFunction = builder.Function("ComplexFunction"); complexFunction.Parameter <ConventionAddress>("address"); complexFunction.Returns <string>(); // Top level function import with entity parameter FunctionConfiguration entityFunction = builder.Function("EntityFunction"); entityFunction.Parameter <ConventionOrder>("order"); entityFunction.Returns <string>(); // Top level function import with optional parameter FunctionConfiguration optionalFunction = builder.Function("OptionalFunction"); optionalFunction.Parameter <int>("param").HasDefaultValue("9"); optionalFunction.Returns <string>(); return(builder.GetEdmModel()); }
public static IEdmModel GetModel() { ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); builder.EntitySet <Customer>("Customers"); builder.EntitySet <Product>("Products"); builder.EntitySet <SalesPerson>("SalesPeople"); builder.EntitySet <EmailAddress>("EmailAddresses"); builder.EntitySet <üCategory>("üCategories"); ActionConfiguration getCustomerById = new ActionConfiguration(builder, "GetCustomerById"); getCustomerById.Parameter <int>("customerId"); getCustomerById.ReturnsFromEntitySet <Customer>("Customers"); ActionConfiguration getSalesPersonById = new ActionConfiguration(builder, "GetSalesPersonById"); getSalesPersonById.Parameter <int>("salesPersonId"); getSalesPersonById.ReturnsFromEntitySet <SalesPerson>("SalesPeople"); ActionConfiguration getAllVIPs = new ActionConfiguration(builder, "GetAllVIPs"); ActionReturnsCollectionFromEntitySet <VIP>(builder, getAllVIPs, "Customers"); builder.Entity <Customer>().ComplexProperty <Address>(c => c.Address); builder.Entity <Customer>().Action("GetRelatedCustomers").ReturnsCollectionFromEntitySet <Customer>("Customers"); ActionConfiguration getBestRelatedCustomer = builder.Entity <Customer>().Action("GetBestRelatedCustomer"); ActionReturnsFromEntitySet <VIP>(builder, getBestRelatedCustomer, "Customers"); ActionConfiguration getVIPS = builder.Entity <Customer>().Collection.Action("GetVIPs"); ActionReturnsCollectionFromEntitySet <VIP>(builder, getVIPS, "Customers"); builder.Entity <Customer>().Collection.Action("GetProducts").ReturnsCollectionFromEntitySet <Product>("Products"); builder.Entity <VIP>().Action("GetSalesPerson").ReturnsFromEntitySet <SalesPerson>("SalesPeople"); builder.Entity <VIP>().Collection.Action("GetSalesPeople").ReturnsCollectionFromEntitySet <SalesPerson>("SalesPeople"); ActionConfiguration getMostProfitable = builder.Entity <VIP>().Collection.Action("GetMostProfitable"); ActionReturnsFromEntitySet <VIP>(builder, getMostProfitable, "Customers"); ActionConfiguration getVIPCustomers = builder.Entity <SalesPerson>().Action("GetVIPCustomers"); ActionReturnsCollectionFromEntitySet <VIP>(builder, getVIPCustomers, "Customers"); ActionConfiguration getVIPCustomersOnCollection = builder.Entity <SalesPerson>().Collection.Action("GetVIPCustomers"); ActionReturnsCollectionFromEntitySet <VIP>(builder, getVIPCustomersOnCollection, "Customers"); builder.Entity <VIP>().HasRequired(v => v.RelationshipManager); builder.Entity <ImportantProduct>().HasRequired(ip => ip.LeadSalesPerson); return(builder.GetEdmModel()); }
private static IEdmModel GetModel(WebRouteConfiguration config) { ODataModelBuilder builder = config.CreateConventionModelBuilder(); EntitySetConfiguration <ActionProduct> products = builder.EntitySet <ActionProduct>("Products"); ActionConfiguration productsByCategory = products.EntityType.Action("GetProductsByCategory"); ActionConfiguration getSpecialProduct = products.EntityType.Action("GetSpecialProduct"); productsByCategory.ReturnsCollectionFromEntitySet <ActionProduct>(products); getSpecialProduct.ReturnsFromEntitySet <ActionProduct>(products); return(builder.GetEdmModel()); }
public override Task <ODataConventionModelBuilder> Run(ODataConventionModelBuilder modelBuilder, CommercePipelineExecutionContext context) { string entitySetName = "Commands"; ActionConfiguration actionConfiguration = modelBuilder.Action("ImportEntity"); actionConfiguration.Parameter <SourceEntityDetail>("sourceEntity"); actionConfiguration.ReturnsFromEntitySet <CommerceCommand>(entitySetName); return(Task.FromResult(modelBuilder)); }
public override Task <ODataConventionModelBuilder> Run(ODataConventionModelBuilder modelBuilder, CommercePipelineExecutionContext context) { Condition.Requires(modelBuilder).IsNotNull($"{this.Name}: The argument cannot be null."); modelBuilder.AddEntityType(typeof(SimplePaymentComponent)); ActionConfiguration addSimplePaymentConfiguration = modelBuilder.Action("AddSimplePayment"); addSimplePaymentConfiguration.Parameter <string>("cartId"); addSimplePaymentConfiguration.Parameter <SimplePaymentComponent>("payment"); addSimplePaymentConfiguration.ReturnsFromEntitySet <CommerceCommand>("Commands"); return(Task.FromResult(modelBuilder)); }
public UnboundActionPathSegmentTest() { ODataModelBuilder builder = new ODataModelBuilder(); builder.EntityType <MyCustomer>().HasKey(c => c.Id).Property(c => c.Name); builder.EntitySet <MyCustomer>("Customers"); ActionConfiguration action = builder.Action("CreateCustomer"); action.ReturnsFromEntitySet <MyCustomer>("Customers"); builder.Action("MyAction").Returns <string>(); builder.Action("ActionWithoutReturn"); _model = builder.GetEdmModel(); _container = _model.EntityContainer; }
/// <summary> /// The execute. /// </summary> /// <param name="modelBuilder"> /// The argument. /// </param> /// <param name="context"> /// The context. /// </param> /// <returns> /// The <see cref="ODataConventionModelBuilder"/>. /// </returns> public override Task <ODataConventionModelBuilder> Run(ODataConventionModelBuilder modelBuilder, CommercePipelineExecutionContext context) { Condition.Requires(modelBuilder).IsNotNull($"{this.Name}: The argument cannot be null."); // Add unbound actions var configuration = modelBuilder.Action("ImportSellableItems"); configuration.ReturnsFromEntitySet <CommerceCommand>("Commands"); var configuration1 = modelBuilder.Action("RunProductImportMinion"); configuration1.ReturnsFromEntitySet <CommerceCommand>("Commands"); ActionConfiguration configuration2 = modelBuilder.Action("RunMinionNow"); configuration2.Parameter <string>("minionFullName"); configuration2.Parameter <string>("environmentName"); configuration2.ReturnsFromEntitySet <CommerceCommand>("Commands"); return(Task.FromResult(modelBuilder)); }
/// <summary> /// The execute. /// </summary> /// <param name="modelBuilder"> /// The argument. /// </param> /// <param name="context"> /// The context. /// </param> /// <returns> /// The <see cref="ODataConventionModelBuilder"/>. /// </returns> public override Task <ODataConventionModelBuilder> Run(ODataConventionModelBuilder modelBuilder, CommercePipelineExecutionContext context) { Condition.Requires(modelBuilder).IsNotNull($"{this.Name}: The argument cannot be null."); // Add the entities ActionConfiguration actionConfiguration1 = modelBuilder.Action("ExportPriceBooks"); actionConfiguration1.Parameter <string>("fileName"); actionConfiguration1.Parameter <string>("mode"); actionConfiguration1.Parameter <int>("maximumItemsPerFile"); actionConfiguration1.Returns <FileCallbackResult>(); ActionConfiguration actionConfiguration2 = modelBuilder.Action("ImportPriceBooks"); actionConfiguration2.Parameter <IFormFile>("importFile"); actionConfiguration2.Parameter <string>("mode"); actionConfiguration2.Parameter <int>("errorThreshold"); actionConfiguration2.ReturnsFromEntitySet <CommerceCommand>("Commands"); return(Task.FromResult(modelBuilder)); }
/// <summary> /// The execute. /// </summary> /// <param name="modelBuilder"> /// The argument. /// </param> /// <param name="context"> /// The context. /// </param> /// <returns> /// The <see cref="ODataConventionModelBuilder"/>. /// </returns> public override Task <ODataConventionModelBuilder> Run(ODataConventionModelBuilder modelBuilder, CommercePipelineExecutionContext context) { Condition.Requires(modelBuilder).IsNotNull($"{this.Name}: The argument cannot be null."); ActionConfiguration addWishlistItemAction = modelBuilder.Action("AddWishListLineItem"); addWishlistItemAction.Parameter <string>("wishlistId"); addWishlistItemAction.Parameter <string>("itemId"); addWishlistItemAction.Parameter <System.Decimal>("quantity"); addWishlistItemAction.ReturnsFromEntitySet <CommerceCommand>("Commands"); ActionConfiguration removeWishlitItemAction = modelBuilder.Action("RemoveWishListLineItem"); removeWishlitItemAction.Parameter <string>("wishlistId"); removeWishlitItemAction.Parameter <string>("cartLineId"); removeWishlitItemAction.ReturnsFromEntitySet <CommerceCommand>("Commands"); return(Task.FromResult(modelBuilder)); }
private IEdmModel GetEdmModel(HttpConfiguration configuration) { ODataConventionModelBuilder builder = ODataModelBuilderMocks.GetModelBuilderMock <ODataConventionModelBuilder>(configuration); builder.EntitySet <ConventionCustomer>("ConventionCustomers"); builder.EntitySet <ConventionOrder>("ConventionOrders"); builder.ComplexType <ConventionPerson>(); builder.EntityType <ConventionCustomer>().ComplexProperty <ConventionAddress>(c => c.Address); // Top level action import ActionConfiguration createConventionCustomerById = builder.Action("CreateConventionCustomerById"); createConventionCustomerById.Parameter <int>("ID"); createConventionCustomerById.ReturnsFromEntitySet <ConventionCustomer>("ConventionCustomers"); // Top level action import without parameter and with a collection of primitive return type ActionConfiguration topCollectionPrimitiveAction = builder.Action("CreateCollectionMessages"); topCollectionPrimitiveAction.ReturnsCollection <string>(); // Top level function import FunctionConfiguration getAllCustomers = builder.Function("GetAllConventionCustomers"); getAllCustomers.ReturnsCollectionFromEntitySet <ConventionCustomer>("ConventionCustomers"); // Top level function import with one parameter FunctionConfiguration getCustomersById = builder.Function("GetConventionCustomerById"); getCustomersById.IsComposable = true; getCustomersById.Parameter <int>("CustomerId"); getCustomersById.ReturnsFromEntitySet <ConventionCustomer>("ConventionCustomers"); // Top level function import with two parameters FunctionConfiguration getOrder = builder.Function("GetConventionOrderByCustomerIdAndOrderName"); getOrder.Parameter <int>("CustomerId"); getOrder.Parameter <string>("OrderName"); getOrder.ReturnsFromEntitySet <ConventionOrder>("ConventionOrders"); return(builder.GetEdmModel()); }
// Builds the EDM model for the OData service, including the OData action definitions. private static IEdmModel GetEdmModel() { var modelBuilder = new ODataConventionModelBuilder(); var moviesEntitySet = modelBuilder.EntitySet <Movie>("Movies"); // Now add actions. // http://odata.github.io/WebApi/#02-03-model-builder-nonconvention // CheckOut // URI: ~/odata/Movies(1)/ODataActionSample.Models.CheckOut ActionConfiguration checkOutAction = modelBuilder.EntityType <Movie>().Action("CheckOut"); checkOutAction.ReturnsFromEntitySet <Movie>("Movies"); // ReturnMovie // URI: ~/odata/Movies(1)/ODataActionSample.Models.Return // Binds to a single entity; no parameters. ActionConfiguration returnAction = modelBuilder.EntityType <Movie>().Action("Return"); returnAction.ReturnsFromEntitySet <Movie>("Movies"); // CheckOutMany action // URI: ~/odata/Movies/ODataActionSample.Models.CheckOutMany // Binds to a collection of entities. This action accepts a collection of parameters. ActionConfiguration checkOutManyAction = modelBuilder.EntityType <Movie>().Collection.Action("CheckOutMany"); checkOutManyAction.CollectionParameter <int>("MovieIDs"); checkOutManyAction.ReturnsCollectionFromEntitySet <Movie>("Movies"); // CreateMovie action // URI: ~/odata/CreateMovie // Unbound action. It is invoked from the service root. ActionConfiguration createMovieAction = modelBuilder.Action("CreateMovie"); createMovieAction.Parameter <string>("Title"); createMovieAction.ReturnsFromEntitySet <Movie>("Movies"); modelBuilder.Namespace = typeof(Movie).Namespace; return(modelBuilder.GetEdmModel()); }
/// <summary> /// The execute. /// </summary> /// <param name="modelBuilder"> /// The argument. /// </param> /// <param name="context"> /// The context. /// </param> /// <returns> /// The <see cref="ODataConventionModelBuilder"/>. /// </returns> public override Task <ODataConventionModelBuilder> Run(ODataConventionModelBuilder modelBuilder, CommercePipelineExecutionContext context) { Condition.Requires(modelBuilder).IsNotNull($"{this.Name}: The argument cannot be null."); // Add the entities //modelBuilder.AddEntityType(typeof(SampleEntity)); // Add the entity sets //modelBuilder.EntitySet<SampleEntity>("Sample"); // Add complex types // Add unbound functions // Add unbound actions //var configuration = modelBuilder.Action("SampleCommand"); //configuration.Parameter<string>("Id"); //configuration.ReturnsFromEntitySet<CommerceCommand>("Commands"); ActionConfiguration actionConfiguration2 = modelBuilder.Action("AddWishListLineItem"); actionConfiguration2.Parameter <string>("wishlistId"); actionConfiguration2.Parameter <string>("itemId"); actionConfiguration2.Parameter <System.Decimal>("quantity"); //string entitySetName2 = "Commands"; actionConfiguration2.ReturnsFromEntitySet <CommerceCommand>("Commands"); ActionConfiguration actionConfiguration3 = modelBuilder.Action("RemoveWishListLineItem"); actionConfiguration3.Parameter <string>("wishlistId"); actionConfiguration3.Parameter <string>("cartLineId"); actionConfiguration3.ReturnsFromEntitySet <CommerceCommand>("Commands"); return(Task.FromResult(modelBuilder)); }
public static IEdmModel GetModel() { HttpConfiguration configuration = new HttpConfiguration(); configuration.Services.Replace(typeof(IAssembliesResolver), new TestAssemblyResolver()); ODataConventionModelBuilder builder = new ODataConventionModelBuilder(configuration); builder.EntitySet <RoutingCustomer>("RoutingCustomers"); builder.EntitySet <Product>("Products"); builder.EntitySet <SalesPerson>("SalesPeople"); builder.EntitySet <EmailAddress>("EmailAddresses"); builder.EntitySet <üCategory>("üCategories"); builder.EntitySet <EnumCustomer>("EnumCustomers"); builder.Singleton <RoutingCustomer>("VipCustomer"); builder.Singleton <Product>("MyProduct"); builder.EntitySet <DateTimeOffsetKeyCustomer>("DateTimeOffsetKeyCustomers"); builder.ComplexType <Dog>(); builder.ComplexType <Cat>(); ActionConfiguration getRoutingCustomerById = builder.Action("GetRoutingCustomerById"); getRoutingCustomerById.Parameter <int>("RoutingCustomerId"); getRoutingCustomerById.ReturnsFromEntitySet <RoutingCustomer>("RoutingCustomers"); ActionConfiguration getSalesPersonById = builder.Action("GetSalesPersonById"); getSalesPersonById.Parameter <int>("salesPersonId"); getSalesPersonById.ReturnsFromEntitySet <SalesPerson>("SalesPeople"); ActionConfiguration getAllVIPs = builder.Action("GetAllVIPs"); ActionReturnsCollectionFromEntitySet <VIP>(builder, getAllVIPs, "RoutingCustomers"); builder.EntityType <RoutingCustomer>().ComplexProperty <Address>(c => c.Address); builder.EntityType <RoutingCustomer>().Action("GetRelatedRoutingCustomers").ReturnsCollectionFromEntitySet <RoutingCustomer>("RoutingCustomers"); ActionConfiguration getBestRelatedRoutingCustomer = builder.EntityType <RoutingCustomer>().Action("GetBestRelatedRoutingCustomer"); ActionReturnsFromEntitySet <VIP>(builder, getBestRelatedRoutingCustomer, "RoutingCustomers"); ActionConfiguration getVIPS = builder.EntityType <RoutingCustomer>().Collection.Action("GetVIPs"); ActionReturnsCollectionFromEntitySet <VIP>(builder, getVIPS, "RoutingCustomers"); builder.EntityType <RoutingCustomer>().Collection.Action("GetProducts").ReturnsCollectionFromEntitySet <Product>("Products"); builder.EntityType <VIP>().Action("GetSalesPerson").ReturnsFromEntitySet <SalesPerson>("SalesPeople"); builder.EntityType <VIP>().Collection.Action("GetSalesPeople").ReturnsCollectionFromEntitySet <SalesPerson>("SalesPeople"); ActionConfiguration getMostProfitable = builder.EntityType <VIP>().Collection.Action("GetMostProfitable"); ActionReturnsFromEntitySet <VIP>(builder, getMostProfitable, "RoutingCustomers"); ActionConfiguration getVIPRoutingCustomers = builder.EntityType <SalesPerson>().Action("GetVIPRoutingCustomers"); ActionReturnsCollectionFromEntitySet <VIP>(builder, getVIPRoutingCustomers, "RoutingCustomers"); ActionConfiguration getVIPRoutingCustomersOnCollection = builder.EntityType <SalesPerson>().Collection.Action("GetVIPRoutingCustomers"); ActionReturnsCollectionFromEntitySet <VIP>(builder, getVIPRoutingCustomersOnCollection, "RoutingCustomers"); builder.EntityType <VIP>().HasRequired(v => v.RelationshipManager); builder.EntityType <ImportantProduct>().HasRequired(ip => ip.LeadSalesPerson); // function bound to an entity FunctionConfiguration topProductId = builder.EntityType <Product>().Function("TopProductId"); topProductId.Returns <int>(); FunctionConfiguration topProductIdByCity = builder.EntityType <Product>().Function("TopProductIdByCity"); topProductIdByCity.Parameter <string>("city"); topProductIdByCity.Returns <string>(); FunctionConfiguration topProductIdByCityAndModel = builder.EntityType <Product>().Function("TopProductIdByCityAndModel"); topProductIdByCityAndModel.Parameter <string>("city"); topProductIdByCityAndModel.Parameter <int>("model"); topProductIdByCityAndModel.Returns <string>(); // function bound to a collection of entities FunctionConfiguration topProductOfAll = builder.EntityType <Product>().Collection.Function("TopProductOfAll"); topProductOfAll.Returns <string>(); FunctionConfiguration topProductOfAllByCity = builder.EntityType <Product>().Collection.Function("TopProductOfAllByCity"); topProductOfAllByCity.Parameter <string>("city"); topProductOfAllByCity.Returns <string>(); FunctionConfiguration topProductOfAllByCityAndModel = builder.EntityType <Product>().Collection.Function("TopProductOfAllByCityAndModel"); topProductOfAllByCityAndModel.Parameter <string>("city"); topProductOfAllByCityAndModel.Parameter <int>("model"); topProductOfAllByCityAndModel.Returns <string>(); // Function bound to the base entity type and derived entity type builder.EntityType <RoutingCustomer>().Function("GetOrdersCount").Returns <string>(); builder.EntityType <VIP>().Function("GetOrdersCount").Returns <string>(); // Overloaded function only bound to the base entity type with one paramter var getOrderCount = builder.EntityType <RoutingCustomer>().Function("GetOrdersCount"); getOrderCount.Parameter <int>("factor"); getOrderCount.Returns <string>(); // Function only bound to the derived entity type builder.EntityType <SpecialVIP>().Function("GetSpecialGuid").Returns <string>(); // Function bound to the collection of the base and the derived entity type builder.EntityType <RoutingCustomer>().Collection.Function("GetAllEmployees").Returns <string>(); builder.EntityType <VIP>().Collection.Function("GetAllEmployees").Returns <string>(); // Bound function with enum type parameters var boundFunction = builder.EntityType <RoutingCustomer>().Collection.Function("BoundFuncWithEnumParameters"); boundFunction.Parameter <SimpleEnum>("SimpleEnum"); boundFunction.Parameter <FlagsEnum>("FlagsEnum"); boundFunction.Returns <string>(); // Bound function with enum type parameter for attribute routing var boundFunctionForAttributeRouting = builder.EntityType <RoutingCustomer>().Collection .Function("BoundFuncWithEnumParameterForAttributeRouting"); boundFunctionForAttributeRouting.Parameter <SimpleEnum>("SimpleEnum"); boundFunctionForAttributeRouting.Returns <string>(); // Unbound function with enum type parameters var function = builder.Function("UnboundFuncWithEnumParameters"); function.Parameter <LongEnum>("LongEnum"); function.Parameter <FlagsEnum>("FlagsEnum"); function.Returns <string>(); // Unbound function builder.Function("UnboundFunction").ReturnsCollection <int>().IsComposable = true; // Action only bound to the derived entity type builder.EntityType <SpecialVIP>().Action("ActionBoundToSpecialVIP"); // Action only bound to the derived entity type builder.EntityType <SpecialVIP>().Collection.Action("ActionBoundToSpecialVIPs"); // Function only bound to the base entity collection type builder.EntityType <RoutingCustomer>().Collection.Function("FunctionBoundToRoutingCustomers").Returns <int>(); // Function only bound to the derived entity collection type builder.EntityType <VIP>().Collection.Function("FunctionBoundToVIPs").Returns <int>(); // Bound function with multiple parameters var functionBoundToProductWithMultipleParamters = builder.EntityType <Product>().Function("FunctionBoundToProductWithMultipleParamters"); functionBoundToProductWithMultipleParamters.Parameter <int>("P1"); functionBoundToProductWithMultipleParamters.Parameter <int>("P2"); functionBoundToProductWithMultipleParamters.Parameter <string>("P3"); functionBoundToProductWithMultipleParamters.Returns <int>(); // Overloaded bound function with no parameter builder.EntityType <Product>().Function("FunctionBoundToProduct").Returns <int>(); // Overloaded bound function with one parameter builder.EntityType <Product>().Function("FunctionBoundToProduct").Returns <int>().Parameter <int>("P1"); // Overloaded bound function with multiple parameters var functionBoundToProduct = builder.EntityType <Product>().Function("FunctionBoundToProduct").Returns <int>(); functionBoundToProduct.Parameter <int>("P1"); functionBoundToProduct.Parameter <int>("P2"); functionBoundToProduct.Parameter <string>("P3"); // Unbound function with one parameter var unboundFunctionWithOneParamters = builder.Function("UnboundFunctionWithOneParamters"); unboundFunctionWithOneParamters.Parameter <int>("P1"); unboundFunctionWithOneParamters.ReturnsFromEntitySet <RoutingCustomer>("RoutingCustomers"); unboundFunctionWithOneParamters.IsComposable = true; // Unbound function with multiple parameters var functionWithMultipleParamters = builder.Function("UnboundFunctionWithMultipleParamters"); functionWithMultipleParamters.Parameter <int>("P1"); functionWithMultipleParamters.Parameter <int>("P2"); functionWithMultipleParamters.Parameter <string>("P3"); functionWithMultipleParamters.Returns <int>(); // Overloaded unbound function with no parameter builder.Function("OverloadUnboundFunction").Returns <int>(); // Overloaded unbound function with one parameter builder.Function("OverloadUnboundFunction").Returns <int>().Parameter <int>("P1"); // Overloaded unbound function with multiple parameters var overloadUnboundFunction = builder.Function("OverloadUnboundFunction").Returns <int>(); overloadUnboundFunction.Parameter <int>("P1"); overloadUnboundFunction.Parameter <int>("P2"); overloadUnboundFunction.Parameter <string>("P3"); return(builder.GetEdmModel()); }
public void CanCreateEdmModel_WithNonBindableAction() { // Arrange ODataModelBuilder builder = new ODataModelBuilder(); // Act ActionConfiguration actionConfiguration = new ActionConfiguration(builder, "ActionName"); actionConfiguration.ReturnsFromEntitySet<Customer>("Customers"); IEdmModel model = builder.GetEdmModel(); // Assert IEdmEntityContainer container = model.EntityContainers().SingleOrDefault(); Assert.NotNull(container); Assert.Equal(1, container.Elements.OfType<IEdmFunctionImport>().Count()); Assert.Equal(1, container.Elements.OfType<IEdmEntitySet>().Count()); IEdmFunctionImport action = container.Elements.OfType<IEdmFunctionImport>().Single(); Assert.False(action.IsComposable); Assert.True(action.IsSideEffecting); Assert.False(action.IsBindable); Assert.Equal("ActionName", action.Name); Assert.NotNull(action.ReturnType); Assert.NotNull(action.EntitySet); Assert.Equal("Customers", (action.EntitySet as IEdmEntitySetReferenceExpression).ReferencedEntitySet.Name); Assert.Equal(typeof(Customer).FullName, (action.EntitySet as IEdmEntitySetReferenceExpression).ReferencedEntitySet.ElementType.FullName()); Assert.Empty(action.Parameters); }
public void CanCreateActionWithEntityReturnType() { // Arrange // Act ODataModelBuilder builder = new ODataModelBuilder(); ActionConfiguration createGoodCustomer = new ActionConfiguration(builder, "CreateGoodCustomer"); createGoodCustomer.ReturnsFromEntitySet<Customer>("GoodCustomers"); ActionConfiguration createBadCustomers = new ActionConfiguration(builder, "CreateBadCustomers"); createBadCustomers.ReturnsCollectionFromEntitySet<Customer>("BadCustomers"); // Assert IEntityTypeConfiguration customer = createGoodCustomer.ReturnType as IEntityTypeConfiguration; Assert.NotNull(customer); Assert.Equal(typeof(Customer).FullName, customer.FullName); IEntitySetConfiguration goodCustomers = builder.EntitySets.SingleOrDefault(s => s.Name == "GoodCustomers"); Assert.NotNull(goodCustomers); Assert.Same(createGoodCustomer.EntitySet, goodCustomers); ICollectionTypeConfiguration customers = createBadCustomers.ReturnType as ICollectionTypeConfiguration; Assert.NotNull(customers); customer = customers.ElementType as IEntityTypeConfiguration; Assert.NotNull(customer); IEntitySetConfiguration badCustomers = builder.EntitySets.SingleOrDefault(s => s.Name == "BadCustomers"); Assert.NotNull(badCustomers); Assert.Same(createBadCustomers.EntitySet, badCustomers); }
// Builds the EDM model for the OData service, including the OData action definitions. private static IEdmModel GetEdmModel() { var modelBuilder = new ODataConventionModelBuilder(); modelBuilder.EntitySet <Vedio>("Vedios"); ActionConfiguration returnAcAction = modelBuilder.Action("ReturnAc"); returnAcAction.Parameter <int>("key"); returnAcAction.ReturnsFromEntitySet <Vedio>("Vedios"); FunctionConfiguration checkOutAction = modelBuilder.Function("CheckOut"); checkOutAction.Parameter <int>("key"); checkOutAction.ReturnsFromEntitySet <Vedio>("Vedios"); ActionConfiguration createMovieAction = modelBuilder.Action("CreateVedio"); createMovieAction.Parameter <Vedio>("vedio"); createMovieAction.ReturnsFromEntitySet <Vedio>("Vedios"); ActionConfiguration ListAcAction = modelBuilder.Action("ListAc"); ListAcAction.Parameter <Window>("windows"); ListAcAction.Returns <int>(); ActionConfiguration checkOutManyAction = modelBuilder.Action("CheckOutMany"); checkOutManyAction.CollectionParameter <int>("MovieIDs"); checkOutManyAction.ReturnsCollectionFromEntitySet <Vedio>("Vedios"); //######################################################################################################// modelBuilder.EntitySet <QueryResult>("QueryResults"); FunctionConfiguration GetRunningTasks = modelBuilder.Function("GetRunningTasks"); GetRunningTasks.Parameter <QueryEntity>("query"); GetRunningTasks.ReturnsCollectionFromEntitySet <QueryResult>("QueryResults"); FunctionConfiguration GetReadyTasks = modelBuilder.Function("GetReadyTasks"); GetReadyTasks.Parameter <QueryEntity>("query"); GetReadyTasks.ReturnsCollectionFromEntitySet <QueryResult>("QueryResults"); //######################################################################################################// ActionConfiguration StartProcess = modelBuilder.Action("StartProcess"); StartProcess.Parameter <WfRunner>("WfRunner"); StartProcess.Returns <int>(); ActionConfiguration RunProcess = modelBuilder.Action("RunProcess"); RunProcess.Parameter <WfRunner>("WfRunner"); RunProcess.Returns <string>(); ActionConfiguration WithdrawProcess = modelBuilder.Action("WithdrawProcess"); WithdrawProcess.Parameter <WfRunner>("WfRunner"); WithdrawProcess.Returns <string>(); ActionConfiguration SendBackProcess = modelBuilder.Action("SendBackProcess"); SendBackProcess.Parameter <WfRunner>("WfRunner"); SendBackProcess.Returns <string>(); ActionConfiguration JumpProcess = modelBuilder.Action("JumpProcess"); JumpProcess.Parameter <WfRunner>("WfRunner"); JumpProcess.Returns <string>(); ActionConfiguration ReverseProcess = modelBuilder.Action("ReverseProcess"); ReverseProcess.Parameter <WfRunner>("WfRunner"); ReverseProcess.Returns <string>(); ActionConfiguration DiscardProcess = modelBuilder.Action("DiscardProcess"); DiscardProcess.Parameter <WfRunner>("WfRunner"); DiscardProcess.Returns <string>(); modelBuilder.Namespace = "WF"; return(modelBuilder.GetEdmModel()); }
public static IEdmModel GetModel() { var configuration = RoutingConfigurationFactory.CreateWithTypes(); ODataConventionModelBuilder builder = ODataConventionModelBuilderFactory.Create(configuration); builder.EntitySet <RoutingCustomer>("RoutingCustomers"); builder.EntitySet <Product>("Products"); builder.EntitySet <SalesPerson>("SalesPeople"); builder.EntitySet <EmailAddress>("EmailAddresses"); builder.EntitySet <üCategory>("üCategories"); builder.EntitySet <EnumCustomer>("EnumCustomers"); builder.Singleton <RoutingCustomer>("VipCustomer"); builder.Singleton <Product>("MyProduct"); builder.EntitySet <DateTimeOffsetKeyCustomer>("DateTimeOffsetKeyCustomers"); builder.EntitySet <Destination>("Destinations"); builder.EntitySet <Incident>("Incidents"); builder.ComplexType <Dog>(); builder.ComplexType <Cat>(); builder.EntityType <SpecialProduct>(); builder.ComplexType <UsAddress>(); ActionConfiguration getRoutingCustomerById = builder.Action("GetRoutingCustomerById"); getRoutingCustomerById.Parameter <int>("RoutingCustomerId"); getRoutingCustomerById.ReturnsFromEntitySet <RoutingCustomer>("RoutingCustomers"); ActionConfiguration getSalesPersonById = builder.Action("GetSalesPersonById"); getSalesPersonById.Parameter <int>("salesPersonId"); getSalesPersonById.ReturnsFromEntitySet <SalesPerson>("SalesPeople"); ActionConfiguration getAllVIPs = builder.Action("GetAllVIPs"); ActionReturnsCollectionFromEntitySet <VIP>(builder, getAllVIPs, "RoutingCustomers"); builder.EntityType <RoutingCustomer>().ComplexProperty <Address>(c => c.Address); builder.EntityType <RoutingCustomer>().Action("GetRelatedRoutingCustomers").ReturnsCollectionFromEntitySet <RoutingCustomer>("RoutingCustomers"); ActionConfiguration getBestRelatedRoutingCustomer = builder.EntityType <RoutingCustomer>().Action("GetBestRelatedRoutingCustomer"); ActionReturnsFromEntitySet <VIP>(builder, getBestRelatedRoutingCustomer, "RoutingCustomers"); ActionConfiguration getVIPS = builder.EntityType <RoutingCustomer>().Collection.Action("GetVIPs"); ActionReturnsCollectionFromEntitySet <VIP>(builder, getVIPS, "RoutingCustomers"); builder.EntityType <RoutingCustomer>().Collection.Action("GetProducts").ReturnsCollectionFromEntitySet <Product>("Products"); builder.EntityType <VIP>().Action("GetSalesPerson").ReturnsFromEntitySet <SalesPerson>("SalesPeople"); builder.EntityType <VIP>().Collection.Action("GetSalesPeople").ReturnsCollectionFromEntitySet <SalesPerson>("SalesPeople"); ActionConfiguration getMostProfitable = builder.EntityType <VIP>().Collection.Action("GetMostProfitable"); ActionReturnsFromEntitySet <VIP>(builder, getMostProfitable, "RoutingCustomers"); ActionConfiguration getVIPRoutingCustomers = builder.EntityType <SalesPerson>().Action("GetVIPRoutingCustomers"); ActionReturnsCollectionFromEntitySet <VIP>(builder, getVIPRoutingCustomers, "RoutingCustomers"); ActionConfiguration getVIPRoutingCustomersOnCollection = builder.EntityType <SalesPerson>().Collection.Action("GetVIPRoutingCustomers"); ActionReturnsCollectionFromEntitySet <VIP>(builder, getVIPRoutingCustomersOnCollection, "RoutingCustomers"); builder.EntityType <VIP>().HasRequired(v => v.RelationshipManager); builder.EntityType <ImportantProduct>().HasRequired(ip => ip.LeadSalesPerson); // function bound to an entity FunctionConfiguration topProductId = builder.EntityType <Product>().Function("TopProductId"); topProductId.Returns <int>(); FunctionConfiguration topProductIdByCity = builder.EntityType <Product>().Function("TopProductIdByCity"); topProductIdByCity.Parameter <string>("city"); topProductIdByCity.Returns <string>(); FunctionConfiguration topProductIdByCityAndModel = builder.EntityType <Product>().Function("TopProductIdByCityAndModel"); topProductIdByCityAndModel.Parameter <string>("city"); topProductIdByCityAndModel.Parameter <int>("model"); topProductIdByCityAndModel.Returns <string>(); FunctionConfiguration optionFunctions = builder.EntityType <Product>().Collection.Function("GetCount").Returns <int>(); optionFunctions.Parameter <double>("minSalary"); optionFunctions.Parameter <double>("maxSalary").Optional(); optionFunctions.Parameter <double>("aveSalary").Optional().HasDefaultValue("1200.99"); // function bound to a collection of entities FunctionConfiguration topProductOfAll = builder.EntityType <Product>().Collection.Function("TopProductOfAll"); topProductOfAll.Returns <string>(); FunctionConfiguration topProductOfAllByCity = builder.EntityType <Product>().Collection.Function("TopProductOfAllByCity"); topProductOfAllByCity.Parameter <string>("city"); topProductOfAllByCity.Returns <string>(); FunctionConfiguration copyProductByCity = builder.EntityType <Product>().Function("CopyProductByCity"); copyProductByCity.Parameter <string>("city"); copyProductByCity.Returns <string>(); FunctionConfiguration topProductOfAllByCityAndModel = builder.EntityType <Product>().Collection.Function("TopProductOfAllByCityAndModel"); topProductOfAllByCityAndModel.Parameter <string>("city"); topProductOfAllByCityAndModel.Parameter <int>("model"); topProductOfAllByCityAndModel.Returns <string>(); // Function bound to the base entity type and derived entity type builder.EntityType <RoutingCustomer>().Function("GetOrdersCount").Returns <string>(); builder.EntityType <VIP>().Function("GetOrdersCount").Returns <string>(); // Overloaded function only bound to the base entity type with one paramter var getOrderCount = builder.EntityType <RoutingCustomer>().Function("GetOrdersCount"); getOrderCount.Parameter <int>("factor"); getOrderCount.Returns <string>(); // Function only bound to the derived entity type builder.EntityType <SpecialVIP>().Function("GetSpecialGuid").Returns <string>(); // Function bound to the collection of the base and the derived entity type builder.EntityType <RoutingCustomer>().Collection.Function("GetAllEmployees").Returns <string>(); builder.EntityType <VIP>().Collection.Function("GetAllEmployees").Returns <string>(); // Bound function with enum type parameters var boundFunction = builder.EntityType <RoutingCustomer>().Collection.Function("BoundFuncWithEnumParameters"); boundFunction.Parameter <SimpleEnum>("SimpleEnum"); boundFunction.Parameter <FlagsEnum>("FlagsEnum"); boundFunction.Returns <string>(); // Bound function with enum type parameter for attribute routing var boundFunctionForAttributeRouting = builder.EntityType <RoutingCustomer>().Collection .Function("BoundFuncWithEnumParameterForAttributeRouting"); boundFunctionForAttributeRouting.Parameter <SimpleEnum>("SimpleEnum"); boundFunctionForAttributeRouting.Returns <string>(); // Unbound function with enum type parameters var function = builder.Function("UnboundFuncWithEnumParameters"); function.Parameter <LongEnum>("LongEnum"); function.Parameter <FlagsEnum>("FlagsEnum"); function.Returns <string>(); // Unbound function builder.Function("UnboundFunction").ReturnsCollection <int>().IsComposable = true; // Action only bound to the derived entity type builder.EntityType <SpecialVIP>().Action("ActionBoundToSpecialVIP"); // Action only bound to the derived entity type builder.EntityType <SpecialVIP>().Collection.Action("ActionBoundToSpecialVIPs"); // Function only bound to the base entity collection type builder.EntityType <RoutingCustomer>().Collection.Function("FunctionBoundToRoutingCustomers").Returns <int>(); // Function only bound to the derived entity collection type builder.EntityType <VIP>().Collection.Function("FunctionBoundToVIPs").Returns <int>(); // Bound function with multiple parameters var functionBoundToProductWithMultipleParamters = builder.EntityType <Product>().Function("FunctionBoundToProductWithMultipleParamters"); functionBoundToProductWithMultipleParamters.Parameter <int>("P1"); functionBoundToProductWithMultipleParamters.Parameter <int>("P2"); functionBoundToProductWithMultipleParamters.Parameter <string>("P3"); functionBoundToProductWithMultipleParamters.Returns <int>(); // Overloaded bound function with no parameter builder.EntityType <Product>().Function("FunctionBoundToProduct").Returns <int>(); // Overloaded bound function with one parameter builder.EntityType <Product>().Function("FunctionBoundToProduct").Returns <int>().Parameter <int>("P1"); // Overloaded bound function with multiple parameters var functionBoundToProduct = builder.EntityType <Product>().Function("FunctionBoundToProduct").Returns <int>(); functionBoundToProduct.Parameter <int>("P1"); functionBoundToProduct.Parameter <int>("P2"); functionBoundToProduct.Parameter <string>("P3"); // Unbound function with one parameter var unboundFunctionWithOneParamters = builder.Function("UnboundFunctionWithOneParamters"); unboundFunctionWithOneParamters.Parameter <int>("P1"); unboundFunctionWithOneParamters.ReturnsFromEntitySet <RoutingCustomer>("RoutingCustomers"); unboundFunctionWithOneParamters.IsComposable = true; // Unbound function with multiple parameters var functionWithMultipleParamters = builder.Function("UnboundFunctionWithMultipleParamters"); functionWithMultipleParamters.Parameter <int>("P1"); functionWithMultipleParamters.Parameter <int>("P2"); functionWithMultipleParamters.Parameter <string>("P3"); functionWithMultipleParamters.Returns <int>(); // Overloaded unbound function with no parameter builder.Function("OverloadUnboundFunction").Returns <int>(); // Overloaded unbound function with one parameter builder.Function("OverloadUnboundFunction").Returns <int>().Parameter <int>("P1"); // Overloaded unbound function with multiple parameters var overloadUnboundFunction = builder.Function("OverloadUnboundFunction").Returns <int>(); overloadUnboundFunction.Parameter <int>("P1"); overloadUnboundFunction.Parameter <int>("P2"); overloadUnboundFunction.Parameter <string>("P3"); var functionWithComplexTypeParameter = builder.EntityType <RoutingCustomer>().Function("CanMoveToAddress").Returns <bool>(); functionWithComplexTypeParameter.Parameter <Address>("address"); var functionWithCollectionOfComplexTypeParameter = builder.EntityType <RoutingCustomer>().Function("MoveToAddresses").Returns <bool>(); functionWithCollectionOfComplexTypeParameter.CollectionParameter <Address>("addresses"); var functionWithCollectionOfPrimitiveTypeParameter = builder.EntityType <RoutingCustomer>().Function("CollectionOfPrimitiveTypeFunction").Returns <bool>(); functionWithCollectionOfPrimitiveTypeParameter.CollectionParameter <int>("intValues"); var functionWithEntityTypeParameter = builder.EntityType <RoutingCustomer>().Function("EntityTypeFunction").Returns <bool>(); functionWithEntityTypeParameter.EntityParameter <Product>("product"); var functionWithCollectionEntityTypeParameter = builder.EntityType <RoutingCustomer>().Function("CollectionEntityTypeFunction").Returns <bool>(); functionWithCollectionEntityTypeParameter.CollectionEntityParameter <Product>("products"); return(builder.GetEdmModel()); }
// Builds the EDM model for the OData service, including the OData action definitions. private static IEdmModel GetModel() { ODataModelBuilder modelBuilder = new ODataConventionModelBuilder(); var moviesEntitySet = modelBuilder.EntitySet <Movie>("Movies"); moviesEntitySet.EntityType.Ignore(m => m.TimeStamp); // Don't expose timestamp to clients // Now add actions to the EDM. // CheckOut // URI: ~/odata/Movies(1)/CheckOut // Transient action. It is not available when the item is already checked out. ActionConfiguration checkout = modelBuilder.Entity <Movie>().TransientAction("CheckOut"); // Provide a function that returns a link to the action, when the action is available, or // returns null when the action is not available. checkout.HasActionLink(ctx => { Movie movie = ctx.EntityInstance as Movie; // Note: In some cases, checking whether the action is available may be relatively expensive. // For example, it might require a DB lookup. // Avoid doing expensive checks inside a loop (i.e., when serializing a feed). Instead, simply // mark the action as available, by returning an action link. // The SkipExpensiveAvailabilityChecks flag says whether to skip expensive checks. If this flag // is true AND your availability check is expensive, skip the check and return a link. // In this sample, the check is not really expensive, but we honor the flag to show how it works. bool createLink = true; if (ctx.SkipExpensiveAvailabilityChecks) { // Caller asked us to skip the availability check. createLink = true; } else if (!movie.IsCheckedOut) // Here is the "expensive" check { createLink = true; } if (createLink) { // Return the URI of the action. return(new Uri(ctx.Url.CreateODataLink( new EntitySetPathSegment(ctx.EntitySet), new KeyValuePathSegment(ODataUriUtils.ConvertToUriLiteral(movie.ID, ODataVersion.V3)), new ActionPathSegment(checkout.Name)))); } else { return(null); } }, followsConventions: true); // "followsConventions" means the action follows OData conventions. checkout.ReturnsFromEntitySet <Movie>("Movies"); // ReturnMovie // URI: ~/odata/Movies(1)/Return // Always bindable. If the movie is not checked out, the action is a no-op. // Binds to a single entity; no parameters. var returnAction = modelBuilder.Entity <Movie>().Action("Return"); returnAction.ReturnsFromEntitySet <Movie>("Movies"); // SetDueDate action // URI: ~/odata/Movies(1)/SetDueDate // Binds to a single entity; takes an action parameter. var setDueDate = modelBuilder.Entity <Movie>().Action("SetDueDate"); setDueDate.Parameter <DateTime>("DueDate"); setDueDate.ReturnsFromEntitySet <Movie>("Movies"); // CheckOut action // URI: ~/odata/Movies/CheckOut // Shows how to bind to a collection, instead of a single entity. // This action also accepts $filter queries. For example: // ~/odata/Movies/CheckOut?$filter=Year eq 2005 var checkOutFromCollection = modelBuilder.Entity <Movie>().Collection.Action("CheckOut"); checkOutFromCollection.ReturnsCollectionFromEntitySet <Movie>("Movies"); // CheckOutMany action // URI: ~/odata/Movies/CheckOutMany // Shows an action that takes a collection parameter. ActionConfiguration checkoutMany = modelBuilder.Entity <Movie>().Collection.Action("CheckOutMany"); checkoutMany.CollectionParameter <int>("MovieIDs"); checkoutMany.ReturnsCollectionFromEntitySet <Movie>("Movies"); // CreateMovie action // URI: ~/odata/CreateMovie // Non-bindable action. You invoke it from the service root. ActionConfiguration createMovie = modelBuilder.Action("CreateMovie"); createMovie.Parameter <string>("Title"); createMovie.ReturnsFromEntitySet <Movie>("Movies"); return(modelBuilder.GetEdmModel()); }
public override Task <ODataConventionModelBuilder> Run(ODataConventionModelBuilder modelBuilder, CommercePipelineExecutionContext context) { Condition.Requires(modelBuilder).IsNotNull($"{this.Name}: The argument cannot be null."); ActionConfiguration updateItemDefinitionAction = modelBuilder.Action("UpdateItemDefinition"); updateItemDefinitionAction.Parameter <string>("itemId"); updateItemDefinitionAction.Parameter <string>("itemDefinition"); updateItemDefinitionAction.ReturnsFromEntitySet <CommerceCommand>("Commands"); ActionConfiguration createPriceCardAction = modelBuilder.Action("CreatePriceCard"); createPriceCardAction.Parameter <string>("itemId"); createPriceCardAction.Parameter <decimal>("price"); createPriceCardAction.ReturnsFromEntitySet <CommerceCommand>("Commands"); ActionConfiguration updatePriceSnapshotAction = modelBuilder.Action("UpdatePriceSnapshot"); updatePriceSnapshotAction.Parameter <string>("itemId"); updatePriceSnapshotAction.Parameter <decimal>("price"); updatePriceSnapshotAction.ReturnsFromEntitySet <CommerceCommand>("Commands"); ActionConfiguration addNewPriceSnapshotAction = modelBuilder.Action("AddNewPriceSnapshot"); addNewPriceSnapshotAction.Parameter <string>("itemId"); addNewPriceSnapshotAction.Parameter <decimal>("price"); addNewPriceSnapshotAction.ReturnsFromEntitySet <CommerceCommand>("Commands"); ActionConfiguration getDeliveryTimeAction = modelBuilder.Action("GetDeliveryTime"); addNewPriceSnapshotAction.CollectionParameter <string>("itemIds"); addNewPriceSnapshotAction.Parameter <string>("primaryInventorySetId"); addNewPriceSnapshotAction.Parameter <string>("secondaryInventorySetId"); addNewPriceSnapshotAction.ReturnsCollection <DeliveryTime>(); ActionConfiguration addPartyAction = modelBuilder.Action("AddParty"); addPartyAction.Parameter <string>("cartId"); addPartyAction.Parameter <Party>("party"); addPartyAction.ReturnsFromEntitySet <CommerceCommand>("Commands"); ActionConfiguration removePartyAction = modelBuilder.Action("RemoveParty"); removePartyAction.Parameter <string>("cartId"); removePartyAction.Parameter <Party>("addressName"); removePartyAction.ReturnsFromEntitySet <CommerceCommand>("Commands"); // Counters var createCounterValueAction = modelBuilder.Action("CreateCounter"); createCounterValueAction.Parameter <string>("counterName"); createCounterValueAction.Parameter <long>("startValue"); createCounterValueAction.ReturnsFromEntitySet <CommerceCommand>("Commands"); var getNextCounterValueAction = modelBuilder.Action("GetNextCounterValue"); getNextCounterValueAction.Parameter <string>("counterName"); getNextCounterValueAction.Returns <long>(); var getOrdernumberForCartAction = modelBuilder.Action("GetOrdernumberForCart"); getOrdernumberForCartAction.Parameter <string>("cartId"); getOrdernumberForCartAction.Returns <string>(); return(Task.FromResult(modelBuilder)); }