Ejemplo n.º 1
0
        public static IEdmModel GetEdmModel()
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            var entityCollection = builder.EntitySet <DollarCountEntity>("DollarCountEntities").EntityType.Collection;

            // Add unbound functions that return collection.
            FunctionConfiguration function = builder.Function("UnboundFunctionReturnsPrimitveCollection");

            function.IsComposable = true;
            function.ReturnsCollection <int>();

            function = builder.Function("UnboundFunctionReturnsEnumCollection");
            function.IsComposable = true;
            function.ReturnsCollection <DollarColor>();

            function = builder.Function("UnboundFunctionReturnsDateTimeOffsetCollection");
            function.IsComposable = true;
            function.ReturnsCollection <DateTimeOffset>();

            function = builder.Function("UnboundFunctionReturnsDateCollection");
            function.IsComposable = true;
            function.ReturnsCollection <Date>();

            function = builder.Function("UnboundFunctionReturnsComplexCollection");
            function.IsComposable = true;
            function.ReturnsCollection <DollarCountComplex>();

            function = builder.Function("UnboundFunctionReturnsEntityCollection");
            function.IsComposable = true;
            function.ReturnsCollectionFromEntitySet <DollarCountEntity>("DollarCountEntities");

            // Add bound functions that return collection.
            function = entityCollection.Function("BoundFunctionReturnsPrimitveCollection");
            function.IsComposable = true;
            function.ReturnsCollection <DateTimeOffset>();

            function = entityCollection.Function("BoundFunctionReturnsEnumCollection");
            function.IsComposable = true;
            function.ReturnsCollection <DollarColor>();

            function = entityCollection.Function("BoundFunctionReturnsDateTimeOffsetCollection");
            function.IsComposable = true;
            function.ReturnsCollection <DateTimeOffset>();

            function = entityCollection.Function("BoundFunctionReturnsComplexCollection");
            function.IsComposable = true;
            function.ReturnsCollection <DollarCountComplex>();

            function = entityCollection.Function("BoundFunctionReturnsEntityCollection");
            function.IsComposable = true;
            function.ReturnsCollectionFromEntitySet <DollarCountEntity>("DollarCountEntities");

            return(builder.GetEdmModel());
        }
Ejemplo n.º 2
0
        public void CanCreateFunctionWithPrimitiveCollectionReturnType()
        {
            // Arrange
            // Act
            ODataModelBuilder     builder  = new ODataModelBuilder();
            FunctionConfiguration function = builder.Function("CreateMessages");

            function.ReturnsCollection <string>();

            // Assert
            Assert.NotNull(function.ReturnType);
            Assert.Equal("Collection(Edm.String)", function.ReturnType.FullName);
        }
        public static IEdmModel GetEdmModel(ODataConventionModelBuilder builder)
        {
            builder.EntitySet <ConventionCustomer>("ConventionCustomers");
            builder.EntitySet <ConventionOrder>("ConventionOrders");

            EnumTypeConfiguration <ConventionGender> enumType = builder.EnumType <ConventionGender>();

            enumType.Member(ConventionGender.Female);
            enumType.Member(ConventionGender.Male);
            #region functions

            FunctionConfiguration getAllCustomers = builder.Function("GetAllConventionCustomers");
            getAllCustomers.ReturnsCollectionFromEntitySet <ConventionCustomer>("ConventionCustomers");
            getAllCustomers.IsComposable = true;

            // Return all the customers whose name contains CustomerName
            FunctionConfiguration getAllCustomersOverload = builder.Function("GetAllConventionCustomers");
            getAllCustomersOverload.ReturnsCollectionFromEntitySet <ConventionCustomer>("ConventionCustomers");
            getAllCustomersOverload.Parameter <string>("CustomerName");
            getAllCustomersOverload.IsComposable = true;

            FunctionConfiguration getCustomersById = builder.Function("GetConventionCustomerById");
            getCustomersById.Parameter <int>("CustomerId");
            getCustomersById.ReturnsFromEntitySet <ConventionCustomer>("ConventionCustomers");
            getCustomersById.IsComposable = true;

            FunctionConfiguration getOrder = builder.Function("GetConventionOrderByCustomerIdAndOrderName");
            getOrder.Parameter <int>("CustomerId");
            getOrder.Parameter <string>("OrderName");
            getOrder.ReturnsFromEntitySet <ConventionOrder>("ConventionOrders");

            FunctionConfiguration getCustomerNameById = builder.Function("GetConventionCustomerNameById");
            getCustomerNameById.Parameter <int>("CustomerId");
            getCustomerNameById.Returns <string>();

            FunctionConfiguration getDefinedGenders = builder.Function("GetDefinedGenders");
            getDefinedGenders.ReturnsCollection <ConventionGender>()
            .IsComposable = true;

            FunctionConfiguration function = builder.Function("AdvancedFunction").Returns <bool>();
            function.CollectionParameter <int>("nums");
            function.CollectionParameter <ConventionGender>("genders");
            function.Parameter <ConventionAddress>("location");
            function.CollectionParameter <ConventionAddress>("addresses");
            function.EntityParameter <ConventionCustomer>("customer");
            function.CollectionEntityParameter <ConventionCustomer>("customers");

            #endregion

            #region actions

            ActionConfiguration resetDataSource = builder.Action("ResetDataSource");

            // bug: error message:  non-binding parameter type must be either Primitive, Complex, Collection of Primitive or a Collection of Complex.

            /*
             * ActionConfiguration createCustomer = builder.Action("CreateCustomer");
             * createCustomer.Parameter<ConventionCustomer>("Customer");
             * createCustomer.ReturnsFromEntitySet<ConventionCustomer>("ConventionCustomers");
             */

            ActionConfiguration udpateAddress = builder.Action("UpdateAddress");
            udpateAddress.Parameter <ConventionAddress>("Address");
            udpateAddress.Parameter <int>("ID");
            udpateAddress.ReturnsCollectionFromEntitySet <ConventionCustomer>("ConventionCustomers");

            ActionConfiguration action = builder.Action("AdvancedAction");
            action.CollectionParameter <int>("nums");
            action.CollectionParameter <ConventionGender>("genders");
            action.Parameter <ConventionAddress>("location");
            action.CollectionParameter <ConventionAddress>("addresses");
            action.EntityParameter <ConventionCustomer>("customer");
            action.CollectionEntityParameter <ConventionCustomer>("customers");

            #endregion

            var schemaNamespace = typeof(ConventionCustomer).Namespace;

            builder.Namespace = schemaNamespace;

            var edmModel  = builder.GetEdmModel();
            var container = edmModel.EntityContainer as EdmEntityContainer;

            #region function imports

            var entitySet = container.FindEntitySet("ConventionCustomers");
            var getCustomersByIdOfEdmFunction = edmModel.FindDeclaredOperations(schemaNamespace + ".GetConventionCustomerById").First() as EdmFunction;
            container.AddFunctionImport("GetConventionCustomerByIdImport", getCustomersByIdOfEdmFunction, new EdmPathExpression(entitySet.Name));

            var functionsOfGetAllConventionCustomers   = edmModel.FindDeclaredOperations(schemaNamespace + ".GetAllConventionCustomers");
            var getAllConventionCustomersOfEdmFunction = functionsOfGetAllConventionCustomers.FirstOrDefault(f => f.Parameters.Count() == 0) as EdmFunction;
            container.AddFunctionImport("GetAllConventionCustomersImport", getAllConventionCustomersOfEdmFunction, new EdmPathExpression(entitySet.Name));

            // TODO delete this overload after bug 1640 is fixed: It can not find the correct overload function if the the function is exposed as a function import.
            var getAllConventionCustomersOverloadOfEdmFunction = functionsOfGetAllConventionCustomers.FirstOrDefault(f => f.Parameters.Count() > 0) as EdmFunction;
            container.AddFunctionImport("GetAllConventionCustomersImport", getAllConventionCustomersOverloadOfEdmFunction, new EdmPathExpression(entitySet.Name));

            var entitySet1 = container.FindEntitySet("ConventionOrders");
            var GetConventionOrderByCustomerIdAndOrderNameOfEdmFunction = edmModel.FindDeclaredOperations(schemaNamespace + ".GetConventionOrderByCustomerIdAndOrderName").First() as EdmFunction;
            container.AddFunctionImport("GetConventionOrderByCustomerIdAndOrderNameImport", GetConventionOrderByCustomerIdAndOrderNameOfEdmFunction, new EdmPathExpression(entitySet1.Name));

            var getConventionCustomerNameByIdOfEdmFunction = edmModel.FindDeclaredOperations(schemaNamespace + ".GetConventionCustomerNameById").First() as EdmFunction;
            container.AddFunctionImport("GetConventionCustomerNameByIdImport", getConventionCustomerNameByIdOfEdmFunction, null);

            #endregion

            #region action imports

            var resetDataSourceOfEdmAction = edmModel.FindDeclaredOperations(schemaNamespace + ".ResetDataSource").FirstOrDefault() as EdmAction;
            container.AddActionImport("ResetDataSourceImport", resetDataSourceOfEdmAction);

            // TODO: it is a potential issue that entity can not be used as an un-bound parameter.

            /*
             * var createCustomerOfEdmAction = edmModel.FindDeclaredOperations(schemaNamespace + ".CreateCustomer").FirstOrDefault() as EdmAction;
             * container.AddActionImport("CreateCustomerImport", createCustomerOfEdmAction);
             */
            var updateAddressOfEdmAction = edmModel.FindDeclaredOperations(schemaNamespace + ".UpdateAddress").FirstOrDefault() as EdmAction;
            container.AddActionImport("UpdateAddressImport", updateAddressOfEdmAction, new EdmPathExpression(entitySet.Name));

            #endregion

            return(edmModel);
        }
Ejemplo n.º 4
0
        private static void MapFascilceOData(ODataModelBuilder builder)
        {
            builder
            .EntitySet <FascicleModel>("Fascicles")
            .EntityType.HasKey(p => p.Id);

            builder
            .EntitySet <FascicleContactModel>("FascicleContacts")
            .EntityType.HasKey(p => p.Id);

            builder
            .EntitySet <GenericDocumentUnitModel>("FascicleDocumentUnits")
            .EntityType.HasKey(p => p.Id);

            builder
            .EntitySet <FascicleFolderTableValuedModel>("FascicleFolders")
            .EntityType.HasKey(p => p.IdFascicleFolder);

            #region [ Functions ]
            FunctionConfiguration getFascicleSummary = builder
                                                       .EntityType <FascicleModel>().Collection
                                                       .Function("GetFascicleSummary");

            getFascicleSummary.Namespace = "FascicleService";
            getFascicleSummary.ReturnsCollectionFromEntitySet <FascicleModel>("Fascicles");
            getFascicleSummary.Parameter <Guid>("uniqueId");

            FunctionConfiguration getFascicleSummaryByYearAndNumber = builder
                                                                      .EntityType <FascicleModel>().Collection
                                                                      .Function("GetFascicleSummaryByYearAndNumber");

            getFascicleSummaryByYearAndNumber.Namespace = "FascicleService";
            getFascicleSummaryByYearAndNumber.ReturnsCollectionFromEntitySet <FascicleModel>("Fascicles");
            getFascicleSummaryByYearAndNumber.Parameter <short>("year");
            getFascicleSummaryByYearAndNumber.Parameter <int>("number");
            getFascicleSummaryByYearAndNumber.Parameter <short>("code");

            FunctionConfiguration getFascicleSummaryByTitle = builder
                                                              .EntityType <FascicleModel>().Collection
                                                              .Function("GetFascicleSummaryByTitle");

            getFascicleSummaryByTitle.Namespace = "FascicleService";
            getFascicleSummaryByTitle.ReturnsCollectionFromEntitySet <FascicleModel>("Fascicles");
            getFascicleSummaryByTitle.Parameter <string>("title");

            FunctionConfiguration getFascicleDocumentUnits = builder
                                                             .EntityType <FascicleModel>().Collection
                                                             .Function("GetFascicleDocumentUnits");

            getFascicleDocumentUnits.Namespace = "FascicleService";
            getFascicleDocumentUnits.ReturnsCollectionFromEntitySet <FascicleModel>("Fascicles");
            getFascicleDocumentUnits.Parameter <Guid>("uniqueId");
            getFascicleDocumentUnits.Parameter <string>("filter");

            FunctionConfiguration getFascicleDocuments = builder
                                                         .EntityType <FascicleModel>().Collection
                                                         .Function("GetFascicleDocuments");

            getFascicleDocuments.Namespace = "FascicleService";
            getFascicleDocuments.ReturnsCollectionFromEntitySet <FascicleModel>("Fascicles");
            getFascicleDocuments.Parameter <Guid>("uniqueId");

            FunctionConfiguration getNextFascicleFolders = builder
                                                           .EntityType <FascicleFolderTableValuedModel>().Collection
                                                           .Function("GetNextFascicleFolders");
            getNextFascicleFolders.Namespace = "FascicleService";
            getNextFascicleFolders.Parameter <Guid>("id");
            getNextFascicleFolders.ReturnsCollectionFromEntitySet <FascicleFolderTableValuedModel>("FascicleFolders");

            FunctionConfiguration getFascicleDocumentUnitFromFolder = builder
                                                                      .EntityType <FascicleFolderTableValuedModel>().Collection
                                                                      .Function("GetFascicleDocumentUnitFromFolder");
            getFascicleDocumentUnitFromFolder.Namespace = "FascicleService";
            getFascicleDocumentUnitFromFolder.Parameter <Guid>("id");
            getFascicleDocumentUnitFromFolder.ReturnsCollection <GenericDocumentUnitModel>();

            FunctionConfiguration getFascicleDocumentFromFolder = builder
                                                                  .EntityType <FascicleFolderTableValuedModel>().Collection
                                                                  .Function("GetFascicleDocumentFromFolder");
            getFascicleDocumentFromFolder.Namespace = "FascicleService";
            getFascicleDocumentFromFolder.Parameter <Guid>("id");
            getFascicleDocumentFromFolder.ReturnsCollection <FascicleDocumentModel>();

            FunctionConfiguration getFascicleFlatDocuments = builder
                                                             .EntityType <FascicleModel>().Collection
                                                             .Function("GetFascicleFlatDocuments");

            getFascicleFlatDocuments.Namespace = "FascicleService";
            getFascicleFlatDocuments.ReturnsCollectionFromEntitySet <FascicleModel>("Fascicles");
            getFascicleFlatDocuments.Parameter <Guid>("uniqueId");

            FunctionConfiguration getFasciclesByMetadataIdentifier = builder
                                                                     .EntityType <FascicleModel>().Collection
                                                                     .Function("GetFasciclesByMetadataIdentifier");

            getFasciclesByMetadataIdentifier.Namespace = "FascicleService";
            getFasciclesByMetadataIdentifier.ReturnsCollectionFromEntitySet <FascicleModel>("Fascicles");
            getFasciclesByMetadataIdentifier.Parameter <string>("name");
            getFasciclesByMetadataIdentifier.Parameter <string>("identifier");

            #endregion

            #region [ Navigation Properties ]

            #endregion
        }