private IEdmModel GetEdmModel()
        {
            EdmModel model = new EdmModel();
            EdmEntityContainer container = new EdmEntityContainer("NS", "Name");
            model.AddElement(container);

            IEdmTypeReference returnType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
            IEdmTypeReference parameterType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);

            container.AddFunctionImport(new EdmFunction("NS", "FunctionWithoutParams", returnType));

            var functionWithOneParam = new EdmFunction("NS", "FunctionWithOneParam", returnType);
            functionWithOneParam.AddParameter("Parameter", parameterType);
            container.AddFunctionImport(functionWithOneParam);

            var functionWithMultipleParams = new EdmFunction("NS", "FunctionWithMultipleParams", returnType);
            functionWithMultipleParams.AddParameter("Parameter1", parameterType);
            functionWithMultipleParams.AddParameter("Parameter2", parameterType);
            functionWithMultipleParams.AddParameter("Parameter3", parameterType);
            container.AddFunctionImport(functionWithMultipleParams);

            container.AddFunctionImport(new EdmFunction("NS", "FunctionWithOverloads", returnType));
            var functionWithOverloads2 = new EdmFunction("NS", "FunctionWithOverloads", returnType);
            functionWithOverloads2.AddParameter("Parameter", parameterType);
            container.AddFunctionImport(functionWithOverloads2);
            var functionWithOverloads3 = new EdmFunction("NS", "FunctionWithOverloads", returnType);
            functionWithOverloads3.AddParameter("Parameter1", parameterType);
            functionWithOverloads3.AddParameter("Parameter2", parameterType);
            functionWithOverloads3.AddParameter("Parameter3", parameterType);
            container.AddFunctionImport(functionWithOverloads3);

            return model;
        }
        public void TestInitialize()
        {
            this.MetadataDocumentUri = new Uri("http://www.myhost.com/myservice.svc/$metadata");

            this.model = new EdmModel();

            EdmEntityContainer defaultContainer = new EdmEntityContainer("TestModel", "DefaultContainer");
            this.model.AddElement(defaultContainer);

            this.cityType = new EdmEntityType("TestModel", "City");
            EdmStructuralProperty cityIdProperty = cityType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(/*isNullable*/false));
            cityType.AddKeys(cityIdProperty);
            cityType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(/*isNullable*/false));
            cityType.AddStructuralProperty("Size", EdmCoreModel.Instance.GetInt32(/*isNullable*/false));
            this.model.AddElement(cityType);

            EdmComplexType complexType = new EdmComplexType("TestModel", "MyComplexType");
            this.model.AddElement(complexType);

            this.operationWithNoOverload = new EdmFunction("TestModel", "FunctionImportWithNoOverload", EdmCoreModel.Instance.GetInt32(true));
            this.operationImportWithNoOverload = defaultContainer.AddFunctionImport("FunctionImportWithNoOverload", operationWithNoOverload);
            this.model.AddElement(operationWithNoOverload);

            this.operationWithOverloadAnd0Param = new EdmFunction("TestModel", "FunctionImportWithOverload", EdmCoreModel.Instance.GetInt32(true));
            this.operationImportWithOverloadAnd0Param = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd0Param);

            this.operationWithOverloadAnd1Param = new EdmFunction("TestModel", "FunctionImportWithOverload", EdmCoreModel.Instance.GetInt32(true));
            this.operationWithOverloadAnd1Param.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false));
            this.model.AddElement(operationWithOverloadAnd1Param);
            this.operationImportWithOverloadAnd1Param = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd1Param);
            
            this.operationWithOverloadAnd2Params = new EdmFunction("TestModel", "FunctionImportWithOverload", EdmCoreModel.Instance.GetInt32(true));
            var cityTypeReference = new EdmEntityTypeReference(this.cityType, isNullable: false);
            this.operationWithOverloadAnd2Params.AddParameter("p1", cityTypeReference);
            this.operationWithOverloadAnd2Params.AddParameter("p2", EdmCoreModel.Instance.GetString(true));
            this.model.AddElement(operationWithOverloadAnd2Params);
            this.operationImportWithOverloadAnd2Params = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd2Params);

            this.operationWithOverloadAnd5Params = new EdmFunction("TestModel", "FunctionImportWithOverload", EdmCoreModel.Instance.GetInt32(true));
            this.operationWithOverloadAnd5Params.AddParameter("p1", new EdmCollectionTypeReference(new EdmCollectionType(cityTypeReference)));
            this.operationWithOverloadAnd5Params.AddParameter("p2", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(isNullable: false))));
            this.operationWithOverloadAnd5Params.AddParameter("p3", EdmCoreModel.Instance.GetString(isNullable: true));
            EdmComplexTypeReference complexTypeReference = new EdmComplexTypeReference(complexType, isNullable: false);
            this.operationWithOverloadAnd5Params.AddParameter("p4", complexTypeReference);
            this.operationWithOverloadAnd5Params.AddParameter("p5", new EdmCollectionTypeReference(new EdmCollectionType(complexTypeReference)));
            this.model.AddElement(operationWithOverloadAnd5Params);
            this.operationImportWithOverloadAnd5Params = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd5Params);
        }
        public void EnsureFunctionImportIsAddedAndWithCorrectSuppliedName()
        {
            EdmEntityContainer container = new EdmEntityContainer("Default", "Container");
            EdmFunction function = new EdmFunction("DS", "TestAction", EdmCoreModel.Instance.GetBoolean(false));
            var functionImport = container.AddFunctionImport("OtherName", function);

            functionImport.Function.Should().Be(function);
            functionImport.Name.Should().Be("OtherName");
            container.Elements.ToArray()[0].Should().Be(functionImport);
        }
        public EdmLibraryExtensionsTests()
        {
            this.model = TestModel.BuildDefaultTestModel();
            this.defaultContainer = (EdmEntityContainer)this.model.FindEntityContainer("Default");
            this.productsSet = this.defaultContainer.FindEntitySet("Products");
            this.productType = (IEdmEntityType)this.model.FindDeclaredType("TestModel.Product");
            this.productTypeReference = new EdmEntityTypeReference(this.productType, false);

            EdmComplexType complexType = new EdmComplexType("TestModel", "MyComplexType");

            this.operationWithNoOverload = new EdmFunction("TestModel", "FunctionImportWithNoOverload", EdmCoreModel.Instance.GetInt32(true));
            this.operationWithNoOverload.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false));
            this.model.AddElement(operationWithNoOverload);
            this.operationImportWithNoOverload = this.defaultContainer.AddFunctionImport("FunctionImportWithNoOverload", operationWithNoOverload);

            this.operationWithOverloadAnd0Param = new EdmFunction("TestModel", "FunctionImportWithNoOverload", EdmCoreModel.Instance.GetInt32(true));
            this.model.AddElement(operationWithOverloadAnd0Param);
            this.operationImportWithOverloadAnd0Param = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd0Param);

            this.operationWithOverloadAnd1Param = new EdmFunction("TestModel", "FunctionImportWithNoOverload", EdmCoreModel.Instance.GetInt32(true));
            this.operationWithOverloadAnd1Param.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false));
            this.model.AddElement(operationWithOverloadAnd1Param);
            this.operationImportWithOverloadAnd1Param = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd1Param);

            this.operationWithOverloadAnd2Params = new EdmFunction("TestModel", "FunctionImportWithNoOverload", EdmCoreModel.Instance.GetInt32(true));
            var productTypeReference = new EdmEntityTypeReference(productType, isNullable: false);
            this.operationWithOverloadAnd2Params.AddParameter("p1", productTypeReference);
            this.operationWithOverloadAnd2Params.AddParameter("p2", EdmCoreModel.Instance.GetString(true));
            this.model.AddElement(operationWithOverloadAnd2Params);
            this.operationImportWithOverloadAnd2Params = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd2Params);

            this.operationWithOverloadAnd5Params = new EdmFunction("TestModel", "FunctionImportWithNoOverload", EdmCoreModel.Instance.GetInt32(true));
            this.operationWithOverloadAnd5Params.AddParameter("p1", new EdmCollectionTypeReference(new EdmCollectionType(productTypeReference)));
            this.operationWithOverloadAnd5Params.AddParameter("p2", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(isNullable: false))));
            this.operationWithOverloadAnd5Params.AddParameter("p3", EdmCoreModel.Instance.GetString(isNullable: true));
            EdmComplexTypeReference complexTypeReference = new EdmComplexTypeReference(complexType, isNullable: false);
            this.operationWithOverloadAnd5Params.AddParameter("p4", complexTypeReference);
            this.operationWithOverloadAnd5Params.AddParameter("p5", new EdmCollectionTypeReference(new EdmCollectionType(complexTypeReference)));
            this.model.AddElement(operationWithOverloadAnd5Params);
            this.operationImportWithOverloadAnd5Params = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd5Params);
        }
        public void HeterogeneousCollectionReaderTest()
        {
            EdmModel model = new EdmModel();
            var cityType = new EdmComplexType("TestModel", "CityType");
            cityType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(true));
            model.AddElement(cityType);

            var addressType = new EdmComplexType("TestModel", "AddressType");
            addressType.AddStructuralProperty("Street", EdmCoreModel.Instance.GetString(true));
            model.AddElement(addressType);

            var testContainer = new EdmEntityContainer("TestModel", "TestContainer");
            model.AddElement(testContainer);
            EdmFunction citiesFunction = new EdmFunction("TestModel", "Cities", EdmCoreModel.GetCollection(cityType.ToTypeReference()));
            model.AddElement(citiesFunction);
            EdmOperationImport citiesFunctionImport = testContainer.AddFunctionImport("Cities", citiesFunction);
            model.Fixup();
            
            // Add some hand-crafted payloads
            IEnumerable<PayloadReaderTestDescriptor> testDescriptors = new PayloadReaderTestDescriptor[]
            {
                // expected type without type names in the payload and heterogeneous items
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = new ComplexInstanceCollection(
                        PayloadBuilder.ComplexValue().Property("Name", PayloadBuilder.PrimitiveValue("Vienna")),
                        PayloadBuilder.ComplexValue().Property("Street", PayloadBuilder.PrimitiveValue("Am Euro Platz")))
                        .ExpectedFunctionImport(citiesFunctionImport)
                        .CollectionName(null),
                    PayloadEdmModel = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_PropertyDoesNotExistOnType", "Street", "TestModel.CityType"),
                },
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations,
                (testDescriptor, testConfiguration) =>
                {
                    testDescriptor.RunTest(testConfiguration);
                });
        }
        private IEdmModel CreateTestModel()
        {
            EdmModel model = new EdmModel();
            EdmEntityContainer defaultContainer = new EdmEntityContainer("TestModel", "Default");
            model.AddElement(defaultContainer);

            var productType = new EdmEntityType("TestModel", "Product");
            EdmStructuralProperty idProperty = new EdmStructuralProperty(productType, "Id", EdmCoreModel.Instance.GetInt32(false));
            productType.AddProperty(idProperty);
            productType.AddKeys(idProperty);
            productType.AddProperty(new EdmStructuralProperty(productType, "Name", EdmCoreModel.Instance.GetString(true)));
            model.AddElement(productType);

            var customerType = new EdmEntityType("TestModel", "Customer");
            idProperty = new EdmStructuralProperty(customerType, "Id", EdmCoreModel.Instance.GetInt32(false));
            customerType.AddProperty(idProperty);
            customerType.AddKeys(idProperty);
            customerType.AddProperty(new EdmStructuralProperty(customerType, "Name", EdmCoreModel.Instance.GetString(true)));
            model.AddElement(productType);

            defaultContainer.AddEntitySet("Products", productType);
            defaultContainer.AddEntitySet("Customers", customerType);
            defaultContainer.AddSingleton("SingleProduct", productType);
            defaultContainer.AddSingleton("SingleCustomer", customerType);

            EdmAction action = new EdmAction("TestModel", "SimpleAction", null/*returnType*/, false /*isBound*/, null /*entitySetPath*/);
            model.AddElement(action);
            defaultContainer.AddActionImport("SimpleActionImport", action);

            EdmFunction function1 = new EdmFunction("TestModel", "SimpleFunction1", EdmCoreModel.Instance.GetInt32(false), false /*isbound*/, null, true);
            function1.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false));
            defaultContainer.AddFunctionImport("SimpleFunctionImport1", function1);

            EdmFunction function2 = new EdmFunction("TestModel", "SimpleFunction2", EdmCoreModel.Instance.GetInt32(false), false /*isbound*/, null, true);
            function2.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false));
            defaultContainer.AddFunctionImport("SimpleFunctionImport2", function1, null, true /*IncludeInServiceDocument*/);

            return model;
        }
        static ODataJsonLightEntryAndFeedDeserializerTests()
        {
            EdmModel tmpModel = new EdmModel();
            EdmComplexType complexType = new EdmComplexType("TestNamespace", "TestComplexType");
            complexType.AddProperty(new EdmStructuralProperty(complexType, "StringProperty", EdmCoreModel.Instance.GetString(false)));
            tmpModel.AddElement(complexType);

            EntityType = new EdmEntityType("TestNamespace", "TestEntityType");
            tmpModel.AddElement(EntityType);
            var keyProperty = new EdmStructuralProperty(EntityType, "ID", EdmCoreModel.Instance.GetInt32(false));
            EntityType.AddKeys(new IEdmStructuralProperty[] { keyProperty });
            EntityType.AddProperty(keyProperty);

            var defaultContainer = new EdmEntityContainer("TestNamespace", "DefaultContainer_sub");
            tmpModel.AddElement(defaultContainer);
            EntitySet = new EdmEntitySet(defaultContainer, "TestEntitySet", EntityType);
            defaultContainer.AddElement(EntitySet);

            Action = new EdmAction("TestNamespace", "DoSomething", null, true, null);
            Action.AddParameter("p1", new EdmEntityTypeReference(EntityType, false));
            tmpModel.AddElement(Action);

            ActionImport = defaultContainer.AddActionImport("DoSomething", Action);

            var serviceOperationFunction = new EdmFunction("TestNamespace", "ServiceOperation", EdmCoreModel.Instance.GetInt32(true));
            defaultContainer.AddFunctionImport("ServiceOperation", serviceOperationFunction);
            tmpModel.AddElement(serviceOperationFunction);

            tmpModel.AddElement(new EdmTerm("custom", "DateTimeOffsetAnnotation", EdmPrimitiveTypeKind.DateTimeOffset));
            tmpModel.AddElement(new EdmTerm("custom", "DateAnnotation", EdmPrimitiveTypeKind.Date));
            tmpModel.AddElement(new EdmTerm("custom", "TimeOfDayAnnotation", EdmPrimitiveTypeKind.TimeOfDay));

            EdmModel = TestUtils.WrapReferencedModelsToMainModel("TestNamespace", "DefaultContainer", tmpModel);
            MessageReaderSettingsReadAndValidateCustomInstanceAnnotations = new ODataMessageReaderSettings { ShouldIncludeAnnotation = ODataUtils.CreateAnnotationFilter("*") };
            MessageReaderSettingsIgnoreInstanceAnnotations = new ODataMessageReaderSettings();
        }
        public static IEdmModel CreateODataServiceModel(string ns)
        {
            EdmModel model = new EdmModel();
            var defaultContainer = new EdmEntityContainer(ns, "OperationService");
            model.AddElement(defaultContainer);

            #region ComplexType

            var addressType = new EdmComplexType(ns, "Address");
            addressType.AddProperty(new EdmStructuralProperty(addressType, "Street", EdmCoreModel.Instance.GetString(false)));
            addressType.AddProperty(new EdmStructuralProperty(addressType, "City", EdmCoreModel.Instance.GetString(false)));
            addressType.AddProperty(new EdmStructuralProperty(addressType, "PostalCode", EdmCoreModel.Instance.GetString(false)));
            model.AddElement(addressType);

            var homeAddressType = new EdmComplexType(ns, "HomeAddress", addressType, false);
            homeAddressType.AddProperty(new EdmStructuralProperty(homeAddressType, "FamilyName", EdmCoreModel.Instance.GetString(true)));
            model.AddElement(homeAddressType);

            var companyAddressType = new EdmComplexType(ns, "CompanyAddress", addressType, false);
            companyAddressType.AddProperty(new EdmStructuralProperty(companyAddressType, "CompanyName", EdmCoreModel.Instance.GetString(false)));
            model.AddElement(companyAddressType);

            #endregion

            #region EnumType

            var customerLevelType = new EdmEnumType(ns, "CustomerLevel");
            customerLevelType.AddMember("Common", new EdmIntegerConstant(0));
            customerLevelType.AddMember("Silver", new EdmIntegerConstant(1));
            customerLevelType.AddMember("Gold", new EdmIntegerConstant(2));
            model.AddElement(customerLevelType);

            #endregion

            #region EntityType

            var customerType = new EdmEntityType(ns, "Customer");
            var customerIdProperty = new EdmStructuralProperty(customerType, "ID", EdmCoreModel.Instance.GetInt32(false));
            customerType.AddProperty(customerIdProperty);
            customerType.AddKeys(customerIdProperty);
            customerType.AddStructuralProperty("FirstName", EdmCoreModel.Instance.GetString(false));
            customerType.AddStructuralProperty("LastName", EdmCoreModel.Instance.GetString(false));
            customerType.AddStructuralProperty("Address", new EdmComplexTypeReference(addressType, true));
            customerType.AddStructuralProperty("Emails", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(true))));
            customerType.AddStructuralProperty("Level", new EdmEnumTypeReference(customerLevelType, false));
            model.AddElement(customerType);

            var orderType = new EdmEntityType(ns, "Order");
            var orderIdProperty = new EdmStructuralProperty(orderType, "ID", EdmCoreModel.Instance.GetInt32(false));
            orderType.AddProperty(orderIdProperty);
            orderType.AddKeys(orderIdProperty);
            orderType.AddStructuralProperty("OrderDate", EdmCoreModel.Instance.GetDateTimeOffset(false));
            orderType.AddStructuralProperty("Notes", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(true))));
            model.AddElement(orderType);

            var ordersNavigation = customerType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name = "Orders",
                Target = orderType,
                TargetMultiplicity = EdmMultiplicity.Many
            });

            var customerForOrderNavigation = orderType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name = "Customer",
                Target = customerType,
                TargetMultiplicity = EdmMultiplicity.One
            });

            #endregion

            #region EntitySet

            var customerSet = new EdmEntitySet(defaultContainer, "Customers", customerType);
            defaultContainer.AddElement(customerSet);

            var orderSet = new EdmEntitySet(defaultContainer, "Orders", orderType);
            defaultContainer.AddElement(orderSet);

            customerSet.AddNavigationTarget(ordersNavigation, orderSet);
            orderSet.AddNavigationTarget(customerForOrderNavigation, customerSet);

            #endregion

            #region Operations

            //UnBound Action: ResetDataSource
            var resetDataSourceAction = new EdmAction(ns, "ResetDataSource", null, false, null);
            model.AddElement(resetDataSourceAction);
            defaultContainer.AddActionImport(resetDataSourceAction);

            var customerTypeReference = new EdmEntityTypeReference(customerType, true);
            var customerCollectionTypeReference =
                new EdmCollectionTypeReference(new EdmCollectionType(customerTypeReference));
            var addressTypeReference = new EdmComplexTypeReference(addressType, true);
            var addressCollectionTypeRefernce =
                new EdmCollectionTypeReference(new EdmCollectionType(addressTypeReference));
            var stringTypeReference = EdmCoreModel.Instance.GetString(true);
            var stringCollectionTypeReference =
                new EdmCollectionTypeReference(new EdmCollectionType(stringTypeReference));
            var orderTypeReference = new EdmEntityTypeReference(orderType, true);
            var orderCollectionTypeReference =
               new EdmCollectionTypeReference(new EdmCollectionType(orderTypeReference));

            //Bound Function : Bound to Collection Of Entity, Parameter is Complex Value, Return Entity.
            var getCustomerForAddressFunction = new EdmFunction(ns, "GetCustomerForAddress", customerTypeReference, true, new EdmPathExpression("customers"), true);
            getCustomerForAddressFunction.AddParameter("customers", customerCollectionTypeReference);
            getCustomerForAddressFunction.AddParameter("address", addressTypeReference);
            model.AddElement(getCustomerForAddressFunction);

            //Bound Function : Bound to Collection Of Entity, Parameter is Collection of Complex Value, Return Collection Of Entity.
            var getCustomersForAddressesFunction = new EdmFunction(ns, "GetCustomersForAddresses", customerCollectionTypeReference, true, new EdmPathExpression("customers"), true);
            getCustomersForAddressesFunction.AddParameter("customers", customerCollectionTypeReference);
            getCustomersForAddressesFunction.AddParameter("addresses", addressCollectionTypeRefernce);
            model.AddElement(getCustomersForAddressesFunction);

            //Bound Function : Bound to Collection Of Entity, Parameter is Collection of Complex Value, Return Entity
            var getCustomerForAddressesFunction = new EdmFunction(ns, "GetCustomerForAddresses", customerTypeReference, true, new EdmPathExpression("customers"), true);
            getCustomerForAddressesFunction.AddParameter("customers", customerCollectionTypeReference);
            getCustomerForAddressesFunction.AddParameter("addresses", addressCollectionTypeRefernce);
            model.AddElement(getCustomerForAddressesFunction);

            //Bound Function : Bound to Entity, Return Complex Value
            var getCustomerAddressFunction = new EdmFunction(ns, "GetCustomerAddress", addressTypeReference, true, null, true);
            getCustomerAddressFunction.AddParameter("customer", customerTypeReference);
            model.AddElement(getCustomerAddressFunction);

            //Bound Function : Bound to Entity, Parameter is Complex Value, Return Entity
            var verifyCustomerAddressFunction = new EdmFunction(ns, "VerifyCustomerAddress", customerTypeReference, true, new EdmPathExpression("customer"), true);
            verifyCustomerAddressFunction.AddParameter("customer", customerTypeReference);
            verifyCustomerAddressFunction.AddParameter("addresses", addressTypeReference);
            model.AddElement(verifyCustomerAddressFunction);

            //Bound Function : Bound to Entity, Parameter is Entity, Return Entity
            var verifyCustomerByOrderFunction = new EdmFunction(ns, "VerifyCustomerByOrder", customerTypeReference, true, new EdmPathExpression("customer"), true);
            verifyCustomerByOrderFunction.AddParameter("customer", customerTypeReference);
            verifyCustomerByOrderFunction.AddParameter("order", orderTypeReference);
            model.AddElement(verifyCustomerByOrderFunction);

            //Bound Function : Bound to Entity, Parameter is Collection of String, Return Collection of Entity
            var getOrdersFromCustomerByNotesFunction = new EdmFunction(ns, "GetOrdersFromCustomerByNotes", orderCollectionTypeReference, true, new EdmPathExpression("customer/Orders"), true);
            getOrdersFromCustomerByNotesFunction.AddParameter("customer", customerTypeReference);
            getOrdersFromCustomerByNotesFunction.AddParameter("notes", stringCollectionTypeReference);
            model.AddElement(getOrdersFromCustomerByNotesFunction);

            //Bound Function : Bound to Collection Of Entity, Parameter is String, Return Collection of Entity
            var getOrdersByNoteFunction = new EdmFunction(ns, "GetOrdersByNote", orderCollectionTypeReference, true, new EdmPathExpression("orders"), true);
            getOrdersByNoteFunction.AddParameter("orders", orderCollectionTypeReference);
            getOrdersByNoteFunction.AddParameter("note", stringTypeReference);
            model.AddElement(getOrdersByNoteFunction);

            //Bound Function : Bound to Collection Of Entity, Parameter is Collection of String, Return Entity
            var getOrderByNoteFunction = new EdmFunction(ns, "GetOrderByNote", orderTypeReference, true, new EdmPathExpression("orders"), true);
            getOrderByNoteFunction.AddParameter("orders", orderCollectionTypeReference);
            getOrderByNoteFunction.AddParameter("notes", stringCollectionTypeReference);
            model.AddElement(getOrderByNoteFunction);

            //Bound Function : Bound to Collection Of Entity, Parameter is Collection of Entity, Return Collection Of Entity
            var getCustomersByOrdersFunction = new EdmFunction(ns, "GetCustomersByOrders", customerCollectionTypeReference, true, new EdmPathExpression("customers"), true);
            getCustomersByOrdersFunction.AddParameter("customers", customerCollectionTypeReference);
            getCustomersByOrdersFunction.AddParameter("orders", orderCollectionTypeReference);
            model.AddElement(getCustomersByOrdersFunction);

            //Bound Function : Bound to Collection Of Entity, Parameter is Entity, Return Entity
            var getCustomerByOrderFunction = new EdmFunction(ns, "GetCustomerByOrder", customerTypeReference, true, new EdmPathExpression("customers"), true);
            getCustomerByOrderFunction.AddParameter("customers", customerCollectionTypeReference);
            getCustomerByOrderFunction.AddParameter("order", orderTypeReference);
            model.AddElement(getCustomerByOrderFunction);

            // Function Import: Parameter is Collection of Entity, Return Collection Of Entity
            var getCustomersByOrdersUnboundFunction = new EdmFunction(ns, "GetCustomersByOrders", customerCollectionTypeReference, false, null, true);
            getCustomersByOrdersUnboundFunction.AddParameter("orders", orderCollectionTypeReference);
            model.AddElement(getCustomersByOrdersUnboundFunction);
            defaultContainer.AddFunctionImport(getCustomersByOrdersUnboundFunction.Name, getCustomersByOrdersUnboundFunction, new EdmEntitySetReferenceExpression(customerSet));

            // Function Import: Parameter is Collection of Entity, Return Entity
            var getCustomerByOrderUnboundFunction = new EdmFunction(ns, "GetCustomerByOrder", customerTypeReference, false, null, true);
            getCustomerByOrderUnboundFunction.AddParameter("order", orderTypeReference);
            model.AddElement(getCustomerByOrderUnboundFunction);
            defaultContainer.AddFunctionImport(getCustomerByOrderUnboundFunction.Name, getCustomerByOrderUnboundFunction, new EdmEntitySetReferenceExpression(customerSet));

            // Function Import: Bound to Entity, Return Complex Value
            var getCustomerAddressUnboundFunction = new EdmFunction(ns, "GetCustomerAddress", addressTypeReference, false, null, true);
            getCustomerAddressUnboundFunction.AddParameter("customer", customerTypeReference);
            model.AddElement(getCustomerAddressUnboundFunction);
            defaultContainer.AddFunctionImport(getCustomerAddressUnboundFunction.Name, getCustomerAddressUnboundFunction);

            #endregion

            IEnumerable<EdmError> errors;
            model.Validate(out errors);
            if (errors.Any())
            {
                throw new SystemException("The model is not valid, please correct it");
            }

            return model;
        }
        public static IEdmModel CreateTripPinServiceModel(string ns)
        {
            EdmModel model = new EdmModel();
            var defaultContainer = new EdmEntityContainer(ns, "DefaultContainer");
            model.AddElement(defaultContainer);

            var genderType = new EdmEnumType(ns, "PersonGender", isFlags: false);
            genderType.AddMember("Male", new EdmIntegerConstant(0));
            genderType.AddMember("Female", new EdmIntegerConstant(1));
            genderType.AddMember("Unknown", new EdmIntegerConstant(2));
            model.AddElement(genderType);

            var cityType = new EdmComplexType(ns, "City");
            cityType.AddProperty(new EdmStructuralProperty(cityType, "CountryRegion", EdmCoreModel.Instance.GetString(false)));
            cityType.AddProperty(new EdmStructuralProperty(cityType, "Name", EdmCoreModel.Instance.GetString(false)));
            cityType.AddProperty(new EdmStructuralProperty(cityType, "Region", EdmCoreModel.Instance.GetString(false)));
            model.AddElement(cityType);

            var locationType = new EdmComplexType(ns, "Location", null, false, true);
            locationType.AddProperty(new EdmStructuralProperty(locationType, "Address", EdmCoreModel.Instance.GetString(false)));
            locationType.AddProperty(new EdmStructuralProperty(locationType, "City", new EdmComplexTypeReference(cityType, false)));
            model.AddElement(locationType);

            var eventLocationType = new EdmComplexType(ns, "EventLocation", locationType, false, true);
            eventLocationType.AddProperty(new EdmStructuralProperty(eventLocationType, "BuildingInfo", EdmCoreModel.Instance.GetString(true)));
            model.AddElement(eventLocationType);

            var airportLocationType = new EdmComplexType(ns, "AirportLocation", locationType, false, true);
            airportLocationType.AddProperty(new EdmStructuralProperty(airportLocationType, "Loc", EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.GeographyPoint, false)));
            model.AddElement(airportLocationType);

            var photoType = new EdmEntityType(ns, "Photo", null, false, false, true);
            var photoIdProperty = new EdmStructuralProperty(photoType, "Id", EdmCoreModel.Instance.GetInt64(false));
            photoType.AddProperty(photoIdProperty);
            photoType.AddKeys(photoIdProperty);
            photoType.AddProperty(new EdmStructuralProperty(photoType, "Name", EdmCoreModel.Instance.GetString(true)));
            model.AddElement(photoType);

            var photoSet = new EdmEntitySet(defaultContainer, "Photos", photoType);
            defaultContainer.AddElement(photoSet);

            var personType = new EdmEntityType(ns, "Person", null, false, /* isOpen */ true);
            var personIdProperty = new EdmStructuralProperty(personType, "UserName", EdmCoreModel.Instance.GetString(false));
            personType.AddProperty(personIdProperty);
            personType.AddKeys(personIdProperty);
            personType.AddProperty(new EdmStructuralProperty(personType, "FirstName", EdmCoreModel.Instance.GetString(false)));
            personType.AddProperty(new EdmStructuralProperty(personType, "LastName", EdmCoreModel.Instance.GetString(false)));
            personType.AddProperty(new EdmStructuralProperty(personType, "Emails", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(true)))));
            personType.AddProperty(new EdmStructuralProperty(personType, "AddressInfo", new EdmCollectionTypeReference(new EdmCollectionType(new EdmComplexTypeReference(locationType, true)))));
            personType.AddProperty(new EdmStructuralProperty(personType, "Gender", new EdmEnumTypeReference(genderType, true)));
            personType.AddProperty(new EdmStructuralProperty(personType, "Concurrency", EdmCoreModel.Instance.GetInt64(false)));
            model.AddElement(personType);

            var personSet = new EdmEntitySet(defaultContainer, "People", personType);
            defaultContainer.AddElement(personSet);

            var airlineType = new EdmEntityType(ns, "Airline");
            var airlineCodeProp = new EdmStructuralProperty(airlineType, "AirlineCode", EdmCoreModel.Instance.GetString(false));
            airlineType.AddKeys(airlineCodeProp);
            airlineType.AddProperty(airlineCodeProp);
            airlineType.AddProperty(new EdmStructuralProperty(airlineType, "Name", EdmCoreModel.Instance.GetString(false)));

            model.AddElement(airlineType);
            var airlineSet = new EdmEntitySet(defaultContainer, "Airlines", airlineType);
            defaultContainer.AddElement(airlineSet);

            var airportType = new EdmEntityType(ns, "Airport");
            var airportIdType = new EdmStructuralProperty(airportType, "IcaoCode", EdmCoreModel.Instance.GetString(false));
            airportType.AddProperty(airportIdType);
            airportType.AddKeys(airportIdType);
            airportType.AddProperty(new EdmStructuralProperty(airportType, "Name", EdmCoreModel.Instance.GetString(false)));
            airportType.AddProperty(new EdmStructuralProperty(airportType, "IataCode", EdmCoreModel.Instance.GetString(false)));
            airportType.AddProperty(new EdmStructuralProperty(airportType, "Location", new EdmComplexTypeReference(airportLocationType, false)));
            model.AddElement(airportType);

            var airportSet = new EdmEntitySet(defaultContainer, "Airports", airportType);
            defaultContainer.AddElement(airportSet);

            var planItemType = new EdmEntityType(ns, "PlanItem");
            var planItemIdType = new EdmStructuralProperty(planItemType, "PlanItemId", EdmCoreModel.Instance.GetInt32(false));
            planItemType.AddProperty(planItemIdType);
            planItemType.AddKeys(planItemIdType);
            planItemType.AddProperty(new EdmStructuralProperty(planItemType, "ConfirmationCode", EdmCoreModel.Instance.GetString(true)));
            planItemType.AddProperty(new EdmStructuralProperty(planItemType, "StartsAt", EdmCoreModel.Instance.GetDateTimeOffset(true)));
            planItemType.AddProperty(new EdmStructuralProperty(planItemType, "EndsAt", EdmCoreModel.Instance.GetDateTimeOffset(true)));
            planItemType.AddProperty(new EdmStructuralProperty(planItemType, "Duration", EdmCoreModel.Instance.GetDuration(true)));
            model.AddElement(planItemType);

            var publicTransportationType = new EdmEntityType(ns, "PublicTransportation", planItemType);
            publicTransportationType.AddProperty(new EdmStructuralProperty(publicTransportationType, "SeatNumber", EdmCoreModel.Instance.GetString(true)));
            model.AddElement(publicTransportationType);

            var flightType = new EdmEntityType(ns, "Flight", publicTransportationType);
            var flightNumberType = new EdmStructuralProperty(flightType, "FlightNumber", EdmCoreModel.Instance.GetString(false));
            flightType.AddProperty(flightNumberType);
            model.AddElement(flightType);

            var eventType = new EdmEntityType(ns, "Event", planItemType, false, true);
            eventType.AddProperty(new EdmStructuralProperty(eventType, "Description", EdmCoreModel.Instance.GetString(true)));
            eventType.AddProperty(new EdmStructuralProperty(eventType, "OccursAt", new EdmComplexTypeReference(eventLocationType, false)));
            model.AddElement(eventType);

            var tripType = new EdmEntityType(ns, "Trip");
            var tripIdType = new EdmStructuralProperty(tripType, "TripId", EdmCoreModel.Instance.GetInt32(false));
            tripType.AddProperty(tripIdType);
            tripType.AddKeys(tripIdType);
            tripType.AddProperty(new EdmStructuralProperty(tripType, "ShareId", EdmCoreModel.Instance.GetGuid(true)));
            tripType.AddProperty(new EdmStructuralProperty(tripType, "Description", EdmCoreModel.Instance.GetString(true)));
            tripType.AddProperty(new EdmStructuralProperty(tripType, "Name", EdmCoreModel.Instance.GetString(false)));
            tripType.AddProperty(new EdmStructuralProperty(tripType, "Budget", EdmCoreModel.Instance.GetSingle(false)));
            tripType.AddProperty(new EdmStructuralProperty(tripType, "StartsAt", EdmCoreModel.Instance.GetDateTimeOffset(false)));
            tripType.AddProperty(new EdmStructuralProperty(tripType, "EndsAt", EdmCoreModel.Instance.GetDateTimeOffset(false)));
            tripType.AddProperty(new EdmStructuralProperty(tripType, "Tags", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false)))));
            model.AddElement(tripType);

            var friendsnNavigation = personType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "Friends",
                Target = personType,
                TargetMultiplicity = EdmMultiplicity.Many
            });

            var personTripNavigation = personType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "Trips",
                Target = tripType,
                TargetMultiplicity = EdmMultiplicity.Many,
                ContainsTarget = true
            });

            var personPhotoNavigation = personType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "Photo",
                Target = photoType,
                TargetMultiplicity = EdmMultiplicity.ZeroOrOne,
            });

            var tripPhotosNavigation = tripType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "Photos",
                Target = photoType,
                TargetMultiplicity = EdmMultiplicity.Many,
            });

            var tripItemNavigation = tripType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "PlanItems",
                Target = planItemType,
                ContainsTarget = true,
                TargetMultiplicity = EdmMultiplicity.Many
            });

            var flightFromAirportNavigation = flightType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "From",
                Target = airportType,
                TargetMultiplicity = EdmMultiplicity.One
            });

            var flightToAirportNavigation = flightType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "To",
                Target = airportType,
                TargetMultiplicity = EdmMultiplicity.One
            });

            var flightAirlineNavigation = flightType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "Airline",
                Target = airlineType,
                TargetMultiplicity = EdmMultiplicity.One
            });

            var me = new EdmSingleton(defaultContainer, "Me", personType);
            defaultContainer.AddElement(me);

            personSet.AddNavigationTarget(friendsnNavigation, personSet);
            me.AddNavigationTarget(friendsnNavigation, personSet);

            personSet.AddNavigationTarget(flightAirlineNavigation, airlineSet);
            me.AddNavigationTarget(flightAirlineNavigation, airlineSet);

            personSet.AddNavigationTarget(flightFromAirportNavigation, airportSet);
            me.AddNavigationTarget(flightFromAirportNavigation, airportSet);

            personSet.AddNavigationTarget(flightToAirportNavigation, airportSet);
            me.AddNavigationTarget(flightToAirportNavigation, airportSet);

            personSet.AddNavigationTarget(personPhotoNavigation, photoSet);
            me.AddNavigationTarget(personPhotoNavigation, photoSet);

            personSet.AddNavigationTarget(tripPhotosNavigation, photoSet);
            me.AddNavigationTarget(tripPhotosNavigation, photoSet);

            var getFavoriteAirlineFunction = new EdmFunction(ns, "GetFavoriteAirline",
                new EdmEntityTypeReference(airlineType, false), true,
                new EdmPathExpression("person/Trips/PlanItems/Microsoft.OData.SampleService.Models.TripPin.Flight/Airline"), true);
            getFavoriteAirlineFunction.AddParameter("person", new EdmEntityTypeReference(personType, false));
            model.AddElement(getFavoriteAirlineFunction);

            var getInvolvedPeopleFunction = new EdmFunction(ns, "GetInvolvedPeople",
                new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(personType, false))), true, null, true);
            getInvolvedPeopleFunction.AddParameter("trip", new EdmEntityTypeReference(tripType, false));
            model.AddElement(getInvolvedPeopleFunction);

            var getFriendsTripsFunction = new EdmFunction(ns, "GetFriendsTrips",
                new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(tripType, false))),
                true, new EdmPathExpression("person/Friends/Trips"), true);
            getFriendsTripsFunction.AddParameter("person", new EdmEntityTypeReference(personType, false));
            getFriendsTripsFunction.AddParameter("userName", EdmCoreModel.Instance.GetString(false));
            model.AddElement(getFriendsTripsFunction);

            var getNearestAirport = new EdmFunction(ns, "GetNearestAirport",
                new EdmEntityTypeReference(airportType, false),
                false, null, true);
            getNearestAirport.AddParameter("lat", EdmCoreModel.Instance.GetDouble(false));
            getNearestAirport.AddParameter("lon", EdmCoreModel.Instance.GetDouble(false));
            model.AddElement(getNearestAirport);
            var getNearestAirportFunctionImport = (IEdmFunctionImport)defaultContainer.AddFunctionImport("GetNearestAirport", getNearestAirport, new EdmEntitySetReferenceExpression(airportSet), true);

            var resetDataSourceAction = new EdmAction(ns, "ResetDataSource", null, false, null);
            model.AddElement(resetDataSourceAction);
            defaultContainer.AddActionImport(resetDataSourceAction);

            var shareTripAction = new EdmAction(ns, "ShareTrip", null, true, null);
            shareTripAction.AddParameter("person", new EdmEntityTypeReference(personType, false));
            shareTripAction.AddParameter("userName", EdmCoreModel.Instance.GetString(false));
            shareTripAction.AddParameter("tripId", EdmCoreModel.Instance.GetInt32(false));
            model.AddElement(shareTripAction);

            model.SetDescriptionAnnotation(defaultContainer, "TripPin service is a sample service for OData V4.");
            model.SetOptimisticConcurrencyAnnotation(personSet, personType.StructuralProperties().Where(p => p.Name == "Concurrency"));
            // TODO: currently singleton does not support ETag feature
            // model.SetOptimisticConcurrencyAnnotation(me, personType.StructuralProperties().Where(p => p.Name == "Concurrency"));
            model.SetResourcePathCoreAnnotation(personSet, "People");
            model.SetResourcePathCoreAnnotation(me, "Me");
            model.SetResourcePathCoreAnnotation(airlineSet, "Airlines");
            model.SetResourcePathCoreAnnotation(airportSet, "Airports");
            model.SetResourcePathCoreAnnotation(photoSet, "Photos");
            model.SetResourcePathCoreAnnotation(getNearestAirportFunctionImport, "Microsoft.OData.SampleService.Models.TripPin.GetNearestAirport");
            model.SetDereferenceableIDsCoreAnnotation(defaultContainer, true);
            model.SetConventionalIDsCoreAnnotation(defaultContainer, true);
            model.SetPermissionsCoreAnnotation(personType.FindProperty("UserName"), CorePermission.Read);
            model.SetPermissionsCoreAnnotation(airlineType.FindProperty("AirlineCode"), CorePermission.Read);
            model.SetPermissionsCoreAnnotation(airportType.FindProperty("IcaoCode"), CorePermission.Read);
            model.SetPermissionsCoreAnnotation(planItemType.FindProperty("PlanItemId"), CorePermission.Read);
            model.SetPermissionsCoreAnnotation(tripType.FindProperty("TripId"), CorePermission.Read);
            model.SetPermissionsCoreAnnotation(photoType.FindProperty("Id"), CorePermission.Read);
            model.SetImmutableCoreAnnotation(airportType.FindProperty("IataCode"), true);
            model.SetComputedCoreAnnotation(personType.FindProperty("Concurrency"), true);
            model.SetAcceptableMediaTypesCoreAnnotation(photoType, new[] { "image/jpeg" });
            model.SetConformanceLevelCapabilitiesAnnotation(defaultContainer, CapabilitiesConformanceLevelType.Advanced);
            model.SetSupportedFormatsCapabilitiesAnnotation(defaultContainer, new[] { "application/json;odata.metadata=full;IEEE754Compatible=false;odata.streaming=true", "application/json;odata.metadata=minimal;IEEE754Compatible=false;odata.streaming=true", "application/json;odata.metadata=none;IEEE754Compatible=false;odata.streaming=true" });
            model.SetAsynchronousRequestsSupportedCapabilitiesAnnotation(defaultContainer, true);
            model.SetBatchContinueOnErrorSupportedCapabilitiesAnnotation(defaultContainer, false);
            model.SetNavigationRestrictionsCapabilitiesAnnotation(personSet, CapabilitiesNavigationType.None, new[] { new Tuple<IEdmNavigationProperty, CapabilitiesNavigationType>(friendsnNavigation, CapabilitiesNavigationType.Recursive) });
            model.SetFilterFunctionsCapabilitiesAnnotation(defaultContainer, new[] { "contains", "endswith", "startswith", "length", "indexof", "substring", "tolower", "toupper", "trim", "concat", "year", "month", "day", "hour", "minute", "second", "round", "floor", "ceiling", "cast", "isof" });
            model.SetSearchRestrictionsCapabilitiesAnnotation(personSet, true, CapabilitiesSearchExpressions.None);
            model.SetSearchRestrictionsCapabilitiesAnnotation(airlineSet, true, CapabilitiesSearchExpressions.None);
            model.SetSearchRestrictionsCapabilitiesAnnotation(airportSet, true, CapabilitiesSearchExpressions.None);
            model.SetSearchRestrictionsCapabilitiesAnnotation(photoSet, true, CapabilitiesSearchExpressions.None);
            model.SetInsertRestrictionsCapabilitiesAnnotation(personSet, true, new[] { personTripNavigation, friendsnNavigation });
            model.SetInsertRestrictionsCapabilitiesAnnotation(airlineSet, true, null);
            model.SetInsertRestrictionsCapabilitiesAnnotation(airportSet, false, null);
            model.SetInsertRestrictionsCapabilitiesAnnotation(photoSet, true, null);
            // TODO: model.SetUpdateRestrictionsCapabilitiesAnnotation();
            model.SetDeleteRestrictionsCapabilitiesAnnotation(airportSet, false, null);
            model.SetISOCurrencyMeasuresAnnotation(tripType.FindProperty("Budget"), "USD");
            model.SetScaleMeasuresAnnotation(tripType.FindProperty("Budget"), 2);

            return model;
        }
        private static EdmFunction AddFunction(EdmEntityContainer container, string name,
            IEdmTypeReference returnType = null, IEdmEntitySet entitySet = null, IEdmTypeReference bindingParameterType = null)
        {
            returnType = returnType ?? EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
            IEdmExpression expression = entitySet == null ? null : new EdmEntitySetReferenceExpression(entitySet);

            var function = new EdmFunction(
                container.Namespace,
                name,
                returnType,
                isBound: bindingParameterType != null,
                entitySetPathExpression: null,
                isComposable: true);
            if (bindingParameterType != null)
            {
                function.AddParameter("bindingParameter", bindingParameterType);
            }
            container.AddFunctionImport(name, function, expression);

            return function;
        }
        public static IEdmModel OperationImportNameSimpleIdentifier()
        {
            var model = new EdmModel();
            var container = new EdmEntityContainer("Default", "Container");

            var function1 = new EdmFunction("Default", "Function1", EdmCoreModel.Instance.GetInt32(false));
            var function2 = new EdmFunction("Default", "Function2", EdmCoreModel.Instance.GetInt32(false));
            var function3 = new EdmFunction("Default", "Function3", EdmCoreModel.Instance.GetInt32(false));
            var function4 = new EdmFunction("Default", "Function4", EdmCoreModel.Instance.GetInt32(false));
            container.AddFunctionImport("ValidName", function1);
            container.AddFunctionImport("_!@#$%^&*()", function2);
            container.AddFunctionImport("   ", function3);
            container.AddFunctionImport(string.Empty, function4);

            var action1 = new EdmAction("Default", "Action1", EdmCoreModel.Instance.GetInt32(false));
            var action2 = new EdmAction("Default", "Action2", EdmCoreModel.Instance.GetInt32(false));
            model.AddElement(action1);
            model.AddElement(action2);
            container.AddActionImport(new string('F', 480), action1);
            container.AddActionImport(new string('F', 481), action2);

            model.AddElement(container);
            model.AddElement(function1);
            model.AddElement(function2);
            model.AddElement(function3);
            model.AddElement(function4);
            return model;
        }
        internal static IEdmModel GetEdmModel()
        {
            var model = new EdmModel();

            #region Type Definitions

            var FullyQualifiedNamespaceIdType = new EdmTypeDefinition("Fully.Qualified.Namespace", "IdType", EdmPrimitiveTypeKind.Double);
            var FullyQualifiedNamespaceIdTypeReference = new EdmTypeDefinitionReference(FullyQualifiedNamespaceIdType, false);
            model.AddElement(FullyQualifiedNamespaceIdType);

            var FullyQualifiedNamespaceNameType = new EdmTypeDefinition("Fully.Qualified.Namespace", "NameType", EdmPrimitiveTypeKind.String);
            var FullyQualifiedNamespaceNameTypeReference = new EdmTypeDefinitionReference(FullyQualifiedNamespaceNameType, false);
            model.AddElement(FullyQualifiedNamespaceNameType);

            var FullyQualifiedNamespaceUInt16Reference = model.GetUInt16("Fully.Qualified.Namespace", false);
            var FullyQualifiedNamespaceUInt32Reference = model.GetUInt32("Fully.Qualified.Namespace", false);
            var FullyQualifiedNamespaceUInt64Reference = model.GetUInt64("Fully.Qualified.Namespace", false);

            #endregion

            #region Enum Types
            var colorType = new EdmEnumType("Fully.Qualified.Namespace", "ColorPattern", EdmPrimitiveTypeKind.Int64, true);
            colorType.AddMember("Red", new EdmIntegerConstant(1L));
            colorType.AddMember("Blue", new EdmIntegerConstant(2L));
            colorType.AddMember("Yellow", new EdmIntegerConstant(4L));
            colorType.AddMember("Solid", new EdmIntegerConstant(8L));
            colorType.AddMember("Striped", new EdmIntegerConstant(16L));
            colorType.AddMember("SolidRed", new EdmIntegerConstant(9L));
            colorType.AddMember("SolidBlue", new EdmIntegerConstant(10L));
            colorType.AddMember("SolidYellow", new EdmIntegerConstant(12L));
            colorType.AddMember("RedBlueStriped", new EdmIntegerConstant(19L));
            colorType.AddMember("RedYellowStriped", new EdmIntegerConstant(21L));
            colorType.AddMember("BlueYellowStriped", new EdmIntegerConstant(22L));
            model.AddElement(colorType);
            var colorTypeReference = new EdmEnumTypeReference(colorType, false);
            var nullableColorTypeReference = new EdmEnumTypeReference(colorType, true);

            var NonFlagShapeType = new EdmEnumType("Fully.Qualified.Namespace", "NonFlagShape", EdmPrimitiveTypeKind.SByte, false);
            NonFlagShapeType.AddMember("Rectangle", new EdmIntegerConstant(1));
            NonFlagShapeType.AddMember("Triangle", new EdmIntegerConstant(2));
            NonFlagShapeType.AddMember("foursquare", new EdmIntegerConstant(3));
            model.AddElement(NonFlagShapeType);
            #endregion

            #region Structured Types
            var FullyQualifiedNamespacePerson = new EdmEntityType("Fully.Qualified.Namespace", "Person", null, false, false);
            var FullyQualifiedNamespaceEmployee = new EdmEntityType("Fully.Qualified.Namespace", "Employee", FullyQualifiedNamespacePerson, false, false);
            var FullyQualifiedNamespaceManager = new EdmEntityType("Fully.Qualified.Namespace", "Manager", FullyQualifiedNamespaceEmployee, false, false);
            var FullyQualifiedNamespaceOpenEmployee = new EdmEntityType("Fully.Qualified.Namespace", "OpenEmployee", FullyQualifiedNamespaceEmployee, false, true);
            var FullyQualifiedNamespaceDog = new EdmEntityType("Fully.Qualified.Namespace", "Dog", null, false, false);
            var FullyQualifiedNamespaceLion = new EdmEntityType("Fully.Qualified.Namespace", "Lion", null, false, false);
            var FullyQualifiedNamespaceChimera = new EdmEntityType("Fully.Qualified.Namespace", "Chimera", null, false, true);
            var FullyQualifiedNamespacePainting = new EdmEntityType("Fully.Qualified.Namespace", "Painting", null, false, true);
            var FullyQualifiedNamespaceFramedPainting = new EdmEntityType("Fully.Qualified.Namespace", "FramedPainting", FullyQualifiedNamespacePainting, false, true);
            var FullyQualifiedNamespaceUserAccount = new EdmEntityType("Fully.Qualified.Namespace", "UserAccount", null, false, false);
            var FullyQualifiedNamespacePet1 = new EdmEntityType("Fully.Qualified.Namespace", "Pet1", null, false, false);
            var FullyQualifiedNamespacePet2 = new EdmEntityType("Fully.Qualified.Namespace", "Pet2", null, false, false);
            var FullyQualifiedNamespacePet3 = new EdmEntityType("Fully.Qualified.Namespace", "Pet3", null, false, false);
            var FullyQualifiedNamespacePet4 = new EdmEntityType("Fully.Qualified.Namespace", "Pet4", null, false, false);
            var FullyQualifiedNamespacePet5 = new EdmEntityType("Fully.Qualified.Namespace", "Pet5", null, false, false);
            var FullyQualifiedNamespacePet6 = new EdmEntityType("Fully.Qualified.Namespace", "Pet6", null, false, false);

            var FullyQualifiedNamespaceAddress = new EdmComplexType("Fully.Qualified.Namespace", "Address");
            var FullyQualifiedNamespaceOpenAddress = new EdmComplexType("Fully.Qualified.Namespace", "OpenAddress", null, false, true);
            var FullyQualifiedNamespaceHomeAddress = new EdmComplexType("Fully.Qualified.Namespace", "HomeAddress", FullyQualifiedNamespaceAddress);

            var FullyQualifiedNamespacePersonTypeReference = new EdmEntityTypeReference(FullyQualifiedNamespacePerson, true);
            var FullyQualifiedNamespaceEmployeeTypeReference = new EdmEntityTypeReference(FullyQualifiedNamespaceEmployee, true);
            var FullyQualifiedNamespaceManagerTypeReference = new EdmEntityTypeReference(FullyQualifiedNamespaceManager, true);
            var FullyQualifiedNamespaceOpenEmployeeTypeReference = new EdmEntityTypeReference(FullyQualifiedNamespaceOpenEmployee, true);
            var FullyQualifiedNamespaceDogTypeReference = new EdmEntityTypeReference(FullyQualifiedNamespaceDog, true);
            var FullyQualifiedNamespaceLionTypeReference = new EdmEntityTypeReference(FullyQualifiedNamespaceLion, true);
            var FullyQualifiedNamespacePet1TypeReference = new EdmEntityTypeReference(FullyQualifiedNamespacePet1, true);
            var FullyQualifiedNamespacePet2TypeReference = new EdmEntityTypeReference(FullyQualifiedNamespacePet2, true);
            var FullyQualifiedNamespacePet3TypeReference = new EdmEntityTypeReference(FullyQualifiedNamespacePet3, true);
            var FullyQualifiedNamespacePet4TypeReference = new EdmEntityTypeReference(FullyQualifiedNamespacePet4, true);
            var FullyQualifiedNamespacePet5TypeReference = new EdmEntityTypeReference(FullyQualifiedNamespacePet5, true);
            var FullyQualifiedNamespacePet6TypeReference = new EdmEntityTypeReference(FullyQualifiedNamespacePet6, true);
            var FullyQualifiedNamespacePaintingTypeReference = new EdmEntityTypeReference(FullyQualifiedNamespacePainting, true);
            var FullyQualifiedNamespaceFramedPaintingTypeReference = new EdmEntityTypeReference(FullyQualifiedNamespaceFramedPainting, true);
            var FullyQualifiedNamespaceUserAccountTypeReference = new EdmEntityTypeReference(FullyQualifiedNamespaceUserAccount, true);

            var FullyQualifiedNamespaceLion_ID1 = FullyQualifiedNamespaceLion.AddStructuralProperty("ID1", EdmCoreModel.Instance.GetInt32(false));
            var FullyQualifiedNamespaceLion_ID2 = FullyQualifiedNamespaceLion.AddStructuralProperty("ID2", EdmCoreModel.Instance.GetInt32(false));
            FullyQualifiedNamespaceLion.AddStructuralProperty("AngerLevel", EdmCoreModel.Instance.GetDouble(true));
            FullyQualifiedNamespaceLion.AddStructuralProperty("AttackDates", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetDateTimeOffset(true))));
            FullyQualifiedNamespaceLion.AddKeys(new IEdmStructuralProperty[] { FullyQualifiedNamespaceLion_ID1, FullyQualifiedNamespaceLion_ID2, });
            model.AddElement(FullyQualifiedNamespaceLion);

            var FullyQualifiedNamespaceAddressTypeReference = new EdmComplexTypeReference(FullyQualifiedNamespaceAddress, true);
            var FullyQualifiedNamespaceOpenAddressTypeReference = new EdmComplexTypeReference(FullyQualifiedNamespaceOpenAddress, true);
            var FullyQualifiedNamespacePerson_ID = FullyQualifiedNamespacePerson.AddStructuralProperty("ID", EdmCoreModel.Instance.GetInt32(false));
            var FullyQualifiedNamespacePerson_SSN = FullyQualifiedNamespacePerson.AddStructuralProperty("SSN", EdmCoreModel.Instance.GetString(true));
            FullyQualifiedNamespacePerson.AddStructuralProperty("Shoe", EdmCoreModel.Instance.GetString(true));
            FullyQualifiedNamespacePerson.AddStructuralProperty("GeographyPoint", EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.GeographyPoint, true));
            FullyQualifiedNamespacePerson.AddStructuralProperty("GeographyLineString", EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.GeographyLineString, true));
            FullyQualifiedNamespacePerson.AddStructuralProperty("GeographyPolygon", EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.GeographyPolygon, true));
            FullyQualifiedNamespacePerson.AddStructuralProperty("GeometryPoint", EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.GeometryPoint, true));
            FullyQualifiedNamespacePerson.AddStructuralProperty("GeometryLineString", EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.GeometryLineString, true));
            FullyQualifiedNamespacePerson.AddStructuralProperty("GeometryPolygon", EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.GeometryPolygon, true));
            FullyQualifiedNamespacePerson.AddStructuralProperty("GeographyCollection", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.GeographyPoint, true))));
            FullyQualifiedNamespacePerson.AddStructuralProperty("GeometryCollection", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.GeometryPoint, true))));
            var FullyQualifiedNamespacePerson_Name = FullyQualifiedNamespacePerson.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(true));
            var FullyQualifiedNamespacePerson_FirstName = FullyQualifiedNamespacePerson.AddStructuralProperty("FirstName", FullyQualifiedNamespaceNameTypeReference);
            FullyQualifiedNamespacePerson.AddStructuralProperty("Prop.With.Periods", EdmCoreModel.Instance.GetString(true));
            FullyQualifiedNamespacePerson.AddStructuralProperty("MyDate", EdmCoreModel.Instance.GetDate(false));
            FullyQualifiedNamespacePerson.AddStructuralProperty("MyDates", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetDate(true))));
            FullyQualifiedNamespacePerson.AddStructuralProperty("MyTimeOfDay", EdmCoreModel.Instance.GetTimeOfDay(false));
            FullyQualifiedNamespacePerson.AddStructuralProperty("MyTimeOfDays", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetTimeOfDay(true))));
            FullyQualifiedNamespacePerson.AddStructuralProperty("Birthdate", EdmCoreModel.Instance.GetDateTimeOffset(false));
            FullyQualifiedNamespacePerson.AddStructuralProperty("FavoriteDate", EdmCoreModel.Instance.GetDateTimeOffset(true));
            FullyQualifiedNamespacePerson.AddStructuralProperty("TimeEmployed", EdmCoreModel.Instance.GetDuration(true));
            FullyQualifiedNamespacePerson.AddStructuralProperty("MyAddress", FullyQualifiedNamespaceAddressTypeReference);
            FullyQualifiedNamespacePerson.AddStructuralProperty("MyOpenAddress", FullyQualifiedNamespaceOpenAddressTypeReference);
            FullyQualifiedNamespacePerson.AddStructuralProperty("PreviousAddresses", new EdmCollectionTypeReference(new EdmCollectionType(FullyQualifiedNamespaceAddressTypeReference)));
            FullyQualifiedNamespacePerson.AddStructuralProperty("FavoriteColors", new EdmCollectionTypeReference(new EdmCollectionType(colorTypeReference)));
            FullyQualifiedNamespacePerson.AddStructuralProperty("FavoriteNumber", FullyQualifiedNamespaceUInt16Reference);
            FullyQualifiedNamespacePerson.AddStructuralProperty("StockQuantity", FullyQualifiedNamespaceUInt32Reference);
            FullyQualifiedNamespacePerson.AddStructuralProperty("LifeTime", FullyQualifiedNamespaceUInt64Reference);
            FullyQualifiedNamespacePerson.AddKeys(FullyQualifiedNamespacePerson_ID);
            var FullyQualifiedNamespacePerson_MyDog = FullyQualifiedNamespacePerson.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MyDog", TargetMultiplicity = EdmMultiplicity.ZeroOrOne, Target = FullyQualifiedNamespaceDog });
            var FullyQualifiedNamespacePerson_MyRelatedDogs = FullyQualifiedNamespacePerson.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MyFriendsDogs", TargetMultiplicity = EdmMultiplicity.Many, Target = FullyQualifiedNamespaceDog });
            var FullyQualifiedNamespacePerson_MyPaintings = FullyQualifiedNamespacePerson.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MyPaintings", TargetMultiplicity = EdmMultiplicity.Many, Target = FullyQualifiedNamespacePainting });
            var FullyQualifiedNamespacePerson_MyFavoritePainting = FullyQualifiedNamespacePerson.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MyFavoritePainting", TargetMultiplicity = EdmMultiplicity.ZeroOrOne, Target = FullyQualifiedNamespacePainting });
            var FullyQualifiedNamespacePerson_MyLions = FullyQualifiedNamespacePerson.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name = "MyLions",
                TargetMultiplicity = EdmMultiplicity.Many,
                Target = FullyQualifiedNamespaceLion,
                DependentProperties = new List<IEdmStructuralProperty>()
                {
                    FullyQualifiedNamespacePerson_ID
                },
                PrincipalProperties = new List<IEdmStructuralProperty>()
                {
                    FullyQualifiedNamespaceLion_ID1
                }
            });
            FullyQualifiedNamespacePerson.AddUnidirectionalNavigation(
                new EdmNavigationPropertyInfo
                {
                    Name = "MyContainedDog",
                    TargetMultiplicity = EdmMultiplicity.ZeroOrOne,
                    Target = FullyQualifiedNamespaceDog,
                    ContainsTarget = true
                });
            FullyQualifiedNamespacePerson.AddUnidirectionalNavigation(
                new EdmNavigationPropertyInfo
                {
                    Name = "MyContainedChimeras",
                    TargetMultiplicity = EdmMultiplicity.Many,
                    Target = FullyQualifiedNamespaceChimera,
                    ContainsTarget = true
                });

            var FullyQualifiedNamespacePerson_MyPet2Set = FullyQualifiedNamespacePerson.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MyPet2Set", TargetMultiplicity = EdmMultiplicity.Many, Target = FullyQualifiedNamespacePet2, });

            model.AddAlternateKeyAnnotation(FullyQualifiedNamespacePerson, new Dictionary<string, IEdmProperty>()
            {
                {"SocialSN", FullyQualifiedNamespacePerson_SSN}
            });

            model.AddAlternateKeyAnnotation(FullyQualifiedNamespacePerson, new Dictionary<string, IEdmProperty>()
            {
                {"NameAlias", FullyQualifiedNamespacePerson_Name},
                {"FirstNameAlias", FullyQualifiedNamespacePerson_FirstName}
            });

            model.AddElement(FullyQualifiedNamespacePerson);

            FullyQualifiedNamespaceEmployee.AddStructuralProperty("WorkEmail", EdmCoreModel.Instance.GetString(true));
            var FullyQualifiedNamespaceEmployee_PaintingsInOffice = FullyQualifiedNamespaceEmployee.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "PaintingsInOffice", TargetMultiplicity = EdmMultiplicity.Many, Target = FullyQualifiedNamespacePainting });
            var FullyQualifiedNamespaceEmployee_Manager = FullyQualifiedNamespaceEmployee.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Manager", TargetMultiplicity = EdmMultiplicity.ZeroOrOne, Target = FullyQualifiedNamespaceManager });
            var FullyQualifiedNamespaceEmployee_OfficeDog = FullyQualifiedNamespaceDog.AddBidirectionalNavigation
                (
                    new EdmNavigationPropertyInfo()
                    {
                        Name = "EmployeeOwner",
                        TargetMultiplicity = EdmMultiplicity.One,
                        Target = FullyQualifiedNamespaceEmployee
                    },

                    new EdmNavigationPropertyInfo()
                    {
                        Name = "OfficeDog",
                        TargetMultiplicity = EdmMultiplicity.One,
                        Target = FullyQualifiedNamespaceDog
                    }
                );
            model.AddElement(FullyQualifiedNamespaceEmployee);

            FullyQualifiedNamespaceManager.AddStructuralProperty("NumberOfReports", EdmCoreModel.Instance.GetInt32(true));
            var FullyQualifiedNamespaceManager_DirectReports = FullyQualifiedNamespaceManager.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "DirectReports", TargetMultiplicity = EdmMultiplicity.Many, Target = FullyQualifiedNamespaceEmployee });
            model.AddElement(FullyQualifiedNamespaceManager);

            model.AddElement(FullyQualifiedNamespaceOpenEmployee);

            var FullyQualifiedNamespaceDog_ID = FullyQualifiedNamespaceDog.AddStructuralProperty("ID", EdmCoreModel.Instance.GetInt32(false));
            FullyQualifiedNamespaceDog.AddStructuralProperty("Color", EdmCoreModel.Instance.GetString(true));
            FullyQualifiedNamespaceDog.AddStructuralProperty("Nicknames", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(true))));
            FullyQualifiedNamespaceDog.AddStructuralProperty("Breed", EdmCoreModel.Instance.GetString(true));
            FullyQualifiedNamespaceDog.AddStructuralProperty("NamedStream", EdmCoreModel.Instance.GetStream(true));
            FullyQualifiedNamespaceDog.AddKeys(new IEdmStructuralProperty[] { FullyQualifiedNamespaceDog_ID, });
            var FullyQualifiedNamespaceDog_MyPeople = FullyQualifiedNamespaceDog.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MyPeople", TargetMultiplicity = EdmMultiplicity.Many, Target = FullyQualifiedNamespacePerson });
            var FullyQualifiedNamespaceDog_FastestOwner = FullyQualifiedNamespaceDog.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "FastestOwner", TargetMultiplicity = EdmMultiplicity.ZeroOrOne, Target = FullyQualifiedNamespacePerson });
            var FullyQualifiedNamespaceDog_LionWhoAteMe = FullyQualifiedNamespaceDog.AddBidirectionalNavigation(
                new EdmNavigationPropertyInfo()
                {
                    Name = "LionWhoAteMe",
                    TargetMultiplicity = EdmMultiplicity.One,
                    Target = FullyQualifiedNamespaceLion,
                },
                new EdmNavigationPropertyInfo()
                {
                    Name = "DogThatIAte",
                    TargetMultiplicity = EdmMultiplicity.One,
                    Target = FullyQualifiedNamespaceDog,
                    DependentProperties = new List<IEdmStructuralProperty>()
                    { 
                        FullyQualifiedNamespaceLion_ID1
                    },
                    PrincipalProperties = new List<IEdmStructuralProperty>()
                    {
                        FullyQualifiedNamespaceDog_ID
                    }
                });
            var FullyQualifiedNamespaceDog_LionsISaw = FullyQualifiedNamespaceDog.AddBidirectionalNavigation(
                new EdmNavigationPropertyInfo()
                {
                    Name = "LionsISaw",
                    TargetMultiplicity = EdmMultiplicity.Many,
                    Target = FullyQualifiedNamespaceLion,
                },
                new EdmNavigationPropertyInfo()
                {
                    Name = "DogsSeenMe",
                    TargetMultiplicity = EdmMultiplicity.Many,
                    Target = FullyQualifiedNamespaceDog,
                    DependentProperties = new List<IEdmStructuralProperty>()
                    { 
                        FullyQualifiedNamespaceLion_ID1
                    },
                    PrincipalProperties = new List<IEdmStructuralProperty>()
                    {
                        FullyQualifiedNamespaceDog_ID
                    }
                });
            var FullyQualifiedNamespaceLion_Friends = FullyQualifiedNamespaceLion.AddUnidirectionalNavigation(
                new EdmNavigationPropertyInfo()
                {
                    Name = "Friends",
                    TargetMultiplicity = EdmMultiplicity.Many,
                    Target = FullyQualifiedNamespaceLion,
                    DependentProperties = new List<IEdmStructuralProperty>()
                    { 
                        FullyQualifiedNamespaceLion_ID2
                    },
                    PrincipalProperties = new List<IEdmStructuralProperty>()
                    {
                        FullyQualifiedNamespaceLion_ID1
                    }
                });
            model.AddElement(FullyQualifiedNamespaceDog);

            var fullyQualifiedNamespaceChimeraKey1 = FullyQualifiedNamespaceChimera.AddStructuralProperty("Rid", EdmCoreModel.Instance.GetInt32(false));
            var fullyQualifiedNamespaceChimeraKey2 = FullyQualifiedNamespaceChimera.AddStructuralProperty("Gid", EdmPrimitiveTypeKind.Guid);
            var fullyQualifiedNamespaceChimeraKey3 = FullyQualifiedNamespaceChimera.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            var fullyQualifiedNamespaceChimeraKey4 = FullyQualifiedNamespaceChimera.AddStructuralProperty("Upgraded", EdmPrimitiveTypeKind.Boolean);
            FullyQualifiedNamespaceChimera.AddStructuralProperty("Level", EdmPrimitiveTypeKind.Int32);
            FullyQualifiedNamespaceChimera.AddKeys(new IEdmStructuralProperty[] { fullyQualifiedNamespaceChimeraKey1, fullyQualifiedNamespaceChimeraKey2, fullyQualifiedNamespaceChimeraKey3, fullyQualifiedNamespaceChimeraKey4 });
            model.AddElement(FullyQualifiedNamespaceChimera);

            var FullyQualifiedNamespacePainting_ID = FullyQualifiedNamespacePainting.AddStructuralProperty("ID", EdmCoreModel.Instance.GetInt32(false));
            FullyQualifiedNamespacePainting.AddStructuralProperty("Artist", EdmCoreModel.Instance.GetString(true));
            FullyQualifiedNamespacePainting.AddStructuralProperty("Value", EdmCoreModel.Instance.GetDecimal(true));
            FullyQualifiedNamespacePainting.AddStructuralProperty("Colors", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(true))));
            FullyQualifiedNamespacePainting.AddKeys(new IEdmStructuralProperty[] { FullyQualifiedNamespacePainting_ID, });
            var FullyQualifiedNamespacePainting_Owner = FullyQualifiedNamespacePainting.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Owner", TargetMultiplicity = EdmMultiplicity.ZeroOrOne, Target = FullyQualifiedNamespacePerson });
            model.AddElement(FullyQualifiedNamespacePainting);

            FullyQualifiedNamespaceFramedPainting.AddStructuralProperty("FrameColor", EdmCoreModel.Instance.GetString(true));
            model.AddElement(FullyQualifiedNamespaceFramedPainting);

            var FullyQualifiedNamespaceUserAccount_UserName = FullyQualifiedNamespaceUserAccount.AddStructuralProperty("UserName", EdmCoreModel.Instance.GetString(true));
            FullyQualifiedNamespaceUserAccount.AddKeys(new IEdmStructuralProperty[] { FullyQualifiedNamespaceUserAccount_UserName, });
            model.AddElement(FullyQualifiedNamespaceUserAccount);

            FullyQualifiedNamespaceAddress.AddStructuralProperty("Street", EdmCoreModel.Instance.GetString(true));
            FullyQualifiedNamespaceAddress.AddStructuralProperty("City", EdmCoreModel.Instance.GetString(true));
            FullyQualifiedNamespaceAddress.AddStructuralProperty("NextHome", FullyQualifiedNamespaceAddressTypeReference);
            FullyQualifiedNamespaceAddress.AddStructuralProperty("MyNeighbors", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(true))));
            model.AddElement(FullyQualifiedNamespaceAddress);

            FullyQualifiedNamespaceHomeAddress.AddStructuralProperty("HomeNO", EdmCoreModel.Instance.GetString(true));
            model.AddElement(FullyQualifiedNamespaceHomeAddress);

            model.AddElement(FullyQualifiedNamespaceOpenAddress);

            FullyQualifiedNamespacePet1.AddKeys(FullyQualifiedNamespacePet1.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int64, false));
            FullyQualifiedNamespacePet1.AddStructuralProperty("SingleID", EdmPrimitiveTypeKind.Single, false);
            FullyQualifiedNamespacePet1.AddStructuralProperty("DoubleID", EdmPrimitiveTypeKind.Double, false);
            FullyQualifiedNamespacePet1.AddStructuralProperty("DecimalID", EdmPrimitiveTypeKind.Decimal, false);
            FullyQualifiedNamespacePet1.AddStructuralProperty("Color", EdmPrimitiveTypeKind.String);
            model.AddElement(FullyQualifiedNamespacePet1);

            FullyQualifiedNamespacePet2.AddKeys(FullyQualifiedNamespacePet2.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Single, false));
            FullyQualifiedNamespacePet2.AddStructuralProperty("Color", EdmPrimitiveTypeKind.String);
            FullyQualifiedNamespacePet2.AddStructuralProperty("PetColorPattern", colorTypeReference);
            model.AddElement(FullyQualifiedNamespacePet2);

            FullyQualifiedNamespacePet3.AddKeys(FullyQualifiedNamespacePet3.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Double, false));
            FullyQualifiedNamespacePet3.AddStructuralProperty("Color", EdmPrimitiveTypeKind.String);
            model.AddElement(FullyQualifiedNamespacePet3);

            FullyQualifiedNamespacePet4.AddKeys(FullyQualifiedNamespacePet4.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Decimal, false));
            FullyQualifiedNamespacePet4.AddStructuralProperty("Color", EdmPrimitiveTypeKind.String);
            model.AddElement(FullyQualifiedNamespacePet4);

            FullyQualifiedNamespacePet5.AddKeys(FullyQualifiedNamespacePet5.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Boolean, false));
            FullyQualifiedNamespacePet5.AddStructuralProperty("Color", EdmPrimitiveTypeKind.String);
            model.AddElement(FullyQualifiedNamespacePet5);

            FullyQualifiedNamespacePet6.AddKeys(FullyQualifiedNamespacePet6.AddStructuralProperty("ID", FullyQualifiedNamespaceIdTypeReference));
            FullyQualifiedNamespacePet6.AddStructuralProperty("Color", EdmPrimitiveTypeKind.String);
            model.AddElement(FullyQualifiedNamespacePet6);
            #endregion

            #region Operations

            var FullyQualifiedNamespaceGetPet1Function = new EdmFunction("Fully.Qualified.Namespace", "GetPet1", FullyQualifiedNamespacePet1TypeReference, false, null, true);
            FullyQualifiedNamespaceGetPet1Function.AddParameter("id", EdmCoreModel.Instance.GetInt64(false));
            model.AddElement(FullyQualifiedNamespaceGetPet1Function);

            var FullyQualifiedNamespaceGetPet2Function = new EdmFunction("Fully.Qualified.Namespace", "GetPet2", FullyQualifiedNamespacePet2TypeReference, false, null, true);
            FullyQualifiedNamespaceGetPet2Function.AddParameter("id", EdmCoreModel.Instance.GetSingle(false));
            model.AddElement(FullyQualifiedNamespaceGetPet2Function);

            var FullyQualifiedNamespaceGetPet3Function = new EdmFunction("Fully.Qualified.Namespace", "GetPet3", FullyQualifiedNamespacePet3TypeReference, false, null, true);
            FullyQualifiedNamespaceGetPet3Function.AddParameter("id", EdmCoreModel.Instance.GetDouble(false));
            model.AddElement(FullyQualifiedNamespaceGetPet3Function);

            var FullyQualifiedNamespaceGetPet4Function = new EdmFunction("Fully.Qualified.Namespace", "GetPet4", FullyQualifiedNamespacePet4TypeReference, false, null, true);
            FullyQualifiedNamespaceGetPet4Function.AddParameter("id", EdmCoreModel.Instance.GetDecimal(false));
            model.AddElement(FullyQualifiedNamespaceGetPet4Function);

            var FullyQualifiedNamespaceGetPet5Function = new EdmFunction("Fully.Qualified.Namespace", "GetPet5", FullyQualifiedNamespacePet5TypeReference, false, null, true);
            FullyQualifiedNamespaceGetPet5Function.AddParameter("id", EdmCoreModel.Instance.GetBoolean(false));
            model.AddElement(FullyQualifiedNamespaceGetPet5Function);

            var FullyQualifiedNamespaceGetPet6Function = new EdmFunction("Fully.Qualified.Namespace", "GetPet6", FullyQualifiedNamespacePet6TypeReference, false, null, true);
            FullyQualifiedNamespaceGetPet6Function.AddParameter("id", FullyQualifiedNamespaceIdTypeReference);
            model.AddElement(FullyQualifiedNamespaceGetPet6Function);

            var FullyQualifiedNamespaceGetPetCountFunction = new EdmFunction("Fully.Qualified.Namespace", "GetPetCount", FullyQualifiedNamespacePet5TypeReference, false, null, true);
            FullyQualifiedNamespaceGetPetCountFunction.AddParameter("colorPattern", colorTypeReference);
            model.AddElement(FullyQualifiedNamespaceGetPetCountFunction);

            var FullyQualifiedNamespaceTryGetPetCountFunction = new EdmFunction("Fully.Qualified.Namespace", "TryGetPetCount", FullyQualifiedNamespacePet5TypeReference, false, null, true);
            FullyQualifiedNamespaceGetPetCountFunction.AddParameter("colorPattern", nullableColorTypeReference);
            model.AddElement(FullyQualifiedNamespaceTryGetPetCountFunction);

            var FullyQualifiedNamespaceWalkAction = new EdmAction("Fully.Qualified.Namespace", "Walk", FullyQualifiedNamespaceAddressTypeReference, true, null);
            FullyQualifiedNamespaceWalkAction.AddParameter("dog", FullyQualifiedNamespaceDogTypeReference);
            model.AddElement(FullyQualifiedNamespaceWalkAction);

            var FullyQualifiedNamespaceFindMyOwnerFunction = new EdmFunction("Fully.Qualified.Namespace", "FindMyOwner", FullyQualifiedNamespacePersonTypeReference, false, null, false);
            FullyQualifiedNamespaceFindMyOwnerFunction.AddParameter("dogsName", EdmCoreModel.Instance.GetString(true));
            model.AddElement(FullyQualifiedNamespaceFindMyOwnerFunction);

            var FullyQualifiedNamespaceHasHatFunction = new EdmFunction("Fully.Qualified.Namespace", "HasHat", EdmCoreModel.Instance.GetBoolean(true), true, null, false);
            FullyQualifiedNamespaceHasHatFunction.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            model.AddElement(FullyQualifiedNamespaceHasHatFunction);

            var FullyQualifiedNamespaceHasHatFunction2 = new EdmFunction("Fully.Qualified.Namespace", "HasHat", EdmCoreModel.Instance.GetInt32(true), true, null, false);
            FullyQualifiedNamespaceHasHatFunction2.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            FullyQualifiedNamespaceHasHatFunction2.AddParameter("onCat", EdmCoreModel.Instance.GetBoolean(true));
            model.AddElement(FullyQualifiedNamespaceHasHatFunction2);

            var FullyQualifiedNamespaceHasJobFunction = new EdmFunction("Fully.Qualified.Namespace", "HasJob", EdmCoreModel.Instance.GetBoolean(true), true, null, false);
            FullyQualifiedNamespaceHasJobFunction.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            model.AddElement(FullyQualifiedNamespaceHasJobFunction);

            var FullyQualifiedNamespaceAllHaveDogFunction = new EdmFunction("Fully.Qualified.Namespace", "AllHaveDog", EdmCoreModel.Instance.GetBoolean(true), true, null, false);
            FullyQualifiedNamespaceAllHaveDogFunction.AddParameter("people", new EdmCollectionTypeReference(new EdmCollectionType(FullyQualifiedNamespacePersonTypeReference)));
            model.AddElement(FullyQualifiedNamespaceAllHaveDogFunction);

            var FullyQualifiedNamespaceAllHaveDogFunction2 = new EdmFunction("Fully.Qualified.Namespace", "AllHaveDog", EdmCoreModel.Instance.GetBoolean(true), true, null, false);
            FullyQualifiedNamespaceAllHaveDogFunction2.AddParameter("people", new EdmCollectionTypeReference(new EdmCollectionType(FullyQualifiedNamespacePersonTypeReference)));
            FullyQualifiedNamespaceAllHaveDogFunction2.AddParameter("inOffice", EdmCoreModel.Instance.GetBoolean(true));
            model.AddElement(FullyQualifiedNamespaceAllHaveDogFunction2);

            var FullyQualifiedNamespaceFireAllAction = new EdmAction("Fully.Qualified.Namespace", "FireAll", EdmCoreModel.Instance.GetBoolean(true), true, null);
            FullyQualifiedNamespaceFireAllAction.AddParameter("employees", new EdmCollectionTypeReference(new EdmCollectionType(FullyQualifiedNamespacePersonTypeReference)));
            model.AddElement(FullyQualifiedNamespaceFireAllAction);

            var FullyQualifiedNamespaceHasDogFunction = new EdmFunction("Fully.Qualified.Namespace", "HasDog", EdmCoreModel.Instance.GetBoolean(true), true, null, false);
            FullyQualifiedNamespaceHasDogFunction.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            model.AddElement(FullyQualifiedNamespaceHasDogFunction);

            var FullyQualifiedNamespaceHasDogFunction2 = new EdmFunction("Fully.Qualified.Namespace", "HasDog", EdmCoreModel.Instance.GetBoolean(true), true, null, false);
            FullyQualifiedNamespaceHasDogFunction2.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            FullyQualifiedNamespaceHasDogFunction2.AddParameter("inOffice", EdmCoreModel.Instance.GetBoolean(true));
            model.AddElement(FullyQualifiedNamespaceHasDogFunction2);

            var FullyQualifiedNamespaceHasDogFunction3 = new EdmFunction("Fully.Qualified.Namespace", "HasDog", EdmCoreModel.Instance.GetBoolean(true), true, null, false);
            FullyQualifiedNamespaceHasDogFunction3.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            FullyQualifiedNamespaceHasDogFunction3.AddParameter("inOffice", EdmCoreModel.Instance.GetBoolean(true));
            FullyQualifiedNamespaceHasDogFunction3.AddParameter("name", EdmCoreModel.Instance.GetString(true));
            model.AddElement(FullyQualifiedNamespaceHasDogFunction3);

            var FullyQualifiedNamespaceHasDogFunction4 = new EdmFunction("Fully.Qualified.Namespace", "HasDog", EdmCoreModel.Instance.GetBoolean(true), true, null, false);
            FullyQualifiedNamespaceHasDogFunction4.AddParameter("person", FullyQualifiedNamespaceEmployeeTypeReference);
            FullyQualifiedNamespaceHasDogFunction4.AddParameter("inOffice", EdmCoreModel.Instance.GetBoolean(true));
            model.AddElement(FullyQualifiedNamespaceHasDogFunction4);

            var FullyQualifiedNamespaceGetMyDogFunction = new EdmFunction("Fully.Qualified.Namespace", "GetMyDog", FullyQualifiedNamespaceDogTypeReference, true, new EdmPathExpression("person/MyDog"), true);
            FullyQualifiedNamespaceGetMyDogFunction.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            model.AddElement(FullyQualifiedNamespaceGetMyDogFunction);

            var FullyQualifiedNamespaceAllMyFriendsDogsFunction = new EdmFunction("Fully.Qualified.Namespace", "AllMyFriendsDogs", new EdmCollectionTypeReference(new EdmCollectionType(FullyQualifiedNamespaceDogTypeReference)), true, new EdmPathExpression("person/MyFriendsDogs"), true);
            FullyQualifiedNamespaceAllMyFriendsDogsFunction.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            model.AddElement(FullyQualifiedNamespaceAllMyFriendsDogsFunction);

            var FullyQualifiedNamespaceAllMyFriendsDogsNonComposableFunction = new EdmFunction("Fully.Qualified.Namespace", "AllMyFriendsDogsNonComposable", new EdmCollectionTypeReference(new EdmCollectionType(FullyQualifiedNamespaceDogTypeReference)), true, new EdmPathExpression("person/MyFriendsDogs"), false);
            FullyQualifiedNamespaceAllMyFriendsDogsNonComposableFunction.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            model.AddElement(FullyQualifiedNamespaceAllMyFriendsDogsNonComposableFunction);

            var FullyQualifiedNamespaceAllMyFriendsDogsFunction2 = new EdmFunction("Fully.Qualified.Namespace", "AllMyFriendsDogs", new EdmCollectionTypeReference(new EdmCollectionType(FullyQualifiedNamespaceDogTypeReference)), true, new EdmPathExpression("person/MyFriendsDogs"), true);
            FullyQualifiedNamespaceAllMyFriendsDogsFunction2.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            FullyQualifiedNamespaceAllMyFriendsDogsFunction2.AddParameter("inOffice", EdmCoreModel.Instance.GetBoolean(true));
            model.AddElement(FullyQualifiedNamespaceAllMyFriendsDogsFunction2);

            var FullyQualifiedNamespaceAllMyFriendsDogs_NoSetFunction = new EdmFunction("Fully.Qualified.Namespace", "AllMyFriendsDogs_NoSet", new EdmCollectionTypeReference(new EdmCollectionType(FullyQualifiedNamespaceDogTypeReference)), true, null, false);
            FullyQualifiedNamespaceAllMyFriendsDogs_NoSetFunction.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            model.AddElement(FullyQualifiedNamespaceAllMyFriendsDogs_NoSetFunction);

            var FullyQualifiedNamespaceOwnerOfFastestDogFunction = new EdmFunction("Fully.Qualified.Namespace", "OwnerOfFastestDog", FullyQualifiedNamespacePersonTypeReference, true, new EdmPathExpression("dogs/FastestOwner"), true);
            FullyQualifiedNamespaceOwnerOfFastestDogFunction.AddParameter("dogs", new EdmCollectionTypeReference(new EdmCollectionType(FullyQualifiedNamespaceDogTypeReference)));
            model.AddElement(FullyQualifiedNamespaceOwnerOfFastestDogFunction);

            var FullyQualifiedNamespaceOwnsTheseDogsFunction = new EdmFunction("Fully.Qualified.Namespace", "OwnsTheseDogs", EdmCoreModel.Instance.GetBoolean(true), true, null, false);
            FullyQualifiedNamespaceOwnsTheseDogsFunction.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            FullyQualifiedNamespaceOwnsTheseDogsFunction.AddParameter("dogNames", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(true))));
            model.AddElement(FullyQualifiedNamespaceOwnsTheseDogsFunction);

            var FullyQualifiedNamespaceIsInTheUSFunction = new EdmFunction("Fully.Qualified.Namespace", "IsInTheUS", EdmCoreModel.Instance.GetBoolean(true), true, null, false);
            FullyQualifiedNamespaceIsInTheUSFunction.AddParameter("address", FullyQualifiedNamespaceAddressTypeReference);
            model.AddElement(FullyQualifiedNamespaceIsInTheUSFunction);

            var FullyQualifiedNamespaceMoveAction = new EdmAction("Fully.Qualified.Namespace", "Move", EdmCoreModel.Instance.GetBoolean(true), true, null);
            FullyQualifiedNamespaceMoveAction.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            FullyQualifiedNamespaceMoveAction.AddParameter("streetAddress", EdmCoreModel.Instance.GetString(true));

            var FullyQualifiedNamespaceCanMoveToAddressFunction = new EdmFunction("Fully.Qualified.Namespace", "CanMoveToAddress", EdmCoreModel.Instance.GetBoolean(true), true, null, false);
            FullyQualifiedNamespaceCanMoveToAddressFunction.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            FullyQualifiedNamespaceCanMoveToAddressFunction.AddParameter("address", FullyQualifiedNamespaceAddressTypeReference);
            model.AddElement(FullyQualifiedNamespaceCanMoveToAddressFunction);

            var FullyQualifiedNamespaceIsAddressGoodFunction = new EdmFunction("Fully.Qualified.Namespace", "IsAddressGood", EdmCoreModel.Instance.GetBoolean(true), false, null, false);
            FullyQualifiedNamespaceIsAddressGoodFunction.AddParameter("address", FullyQualifiedNamespaceAddressTypeReference);
            model.AddElement(FullyQualifiedNamespaceIsAddressGoodFunction);

            var FullyQualifiedNamespaceCanMoveToAddressesFunction = new EdmFunction("Fully.Qualified.Namespace", "CanMoveToAddresses", EdmCoreModel.Instance.GetBoolean(true), true, null, false);
            FullyQualifiedNamespaceCanMoveToAddressesFunction.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            FullyQualifiedNamespaceCanMoveToAddressesFunction.AddParameter("addresses", new EdmCollectionTypeReference(new EdmCollectionType(FullyQualifiedNamespaceAddressTypeReference)));
            model.AddElement(FullyQualifiedNamespaceCanMoveToAddressesFunction);

            var FullyQualifiedNamespaceIsOlderThanByteFunction = new EdmFunction("Fully.Qualified.Namespace", "IsOlderThanByte", EdmCoreModel.Instance.GetBoolean(true), true, null, false);
            FullyQualifiedNamespaceIsOlderThanByteFunction.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            FullyQualifiedNamespaceIsOlderThanByteFunction.AddParameter("age", EdmCoreModel.Instance.GetByte(true));
            model.AddElement(FullyQualifiedNamespaceIsOlderThanByteFunction);

            var FullyQualifiedNamespaceIsOlderThanSByteFunction = new EdmFunction("Fully.Qualified.Namespace", "IsOlderThanSByte", EdmCoreModel.Instance.GetBoolean(true), true, null, false);
            FullyQualifiedNamespaceIsOlderThanSByteFunction.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            FullyQualifiedNamespaceIsOlderThanSByteFunction.AddParameter("age", EdmCoreModel.Instance.GetSByte(true));
            model.AddElement(FullyQualifiedNamespaceIsOlderThanSByteFunction);

            var FullyQualifiedNamespaceIsOlderThanShortFunction = new EdmFunction("Fully.Qualified.Namespace", "IsOlderThanShort", EdmCoreModel.Instance.GetBoolean(true), true, null, false);
            FullyQualifiedNamespaceIsOlderThanShortFunction.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            FullyQualifiedNamespaceIsOlderThanShortFunction.AddParameter("age", EdmCoreModel.Instance.GetInt16(true));
            model.AddElement(FullyQualifiedNamespaceIsOlderThanShortFunction);

            var FullyQualifiedNamespaceIsOlderThanSingleFunction = new EdmFunction("Fully.Qualified.Namespace", "IsOlderThanSingle", EdmCoreModel.Instance.GetBoolean(true), true, null, false);
            FullyQualifiedNamespaceIsOlderThanSingleFunction.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            FullyQualifiedNamespaceIsOlderThanSingleFunction.AddParameter("age", EdmCoreModel.Instance.GetSingle(true));
            model.AddElement(FullyQualifiedNamespaceIsOlderThanSingleFunction);

            var FullyQualifiedNamespacePaintAction = new EdmAction("Fully.Qualified.Namespace", "Paint", FullyQualifiedNamespacePaintingTypeReference, true, new EdmPathExpression("person/MyPaintings"));
            FullyQualifiedNamespacePaintAction.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            model.AddElement(FullyQualifiedNamespacePaintAction);

            var FullyQualifiedNamespaceMoveAction2 = new EdmAction("Fully.Qualified.Namespace", "Move", EdmCoreModel.Instance.GetBoolean(true), true, null);
            FullyQualifiedNamespaceMoveAction2.AddParameter("employee", FullyQualifiedNamespaceEmployeeTypeReference);
            FullyQualifiedNamespaceMoveAction2.AddParameter("building", EdmCoreModel.Instance.GetInt32(true));
            FullyQualifiedNamespaceMoveAction2.AddParameter("room", EdmCoreModel.Instance.GetInt32(true));
            model.AddElement(FullyQualifiedNamespaceMoveAction2);

            var FullyQualifiedNamespaceRestoreAction = new EdmAction("Fully.Qualified.Namespace", "Restore", EdmCoreModel.Instance.GetBoolean(true), true, null);
            FullyQualifiedNamespaceRestoreAction.AddParameter("painting", FullyQualifiedNamespacePaintingTypeReference);
            model.AddElement(FullyQualifiedNamespaceRestoreAction);

            var FullyQualifiedNamespaceChangeStateAction = new EdmAction("Fully.Qualified.Namespace", "ChangeState", EdmCoreModel.Instance.GetBoolean(true), true, null);
            FullyQualifiedNamespaceChangeStateAction.AddParameter("address", FullyQualifiedNamespaceAddressTypeReference);
            FullyQualifiedNamespaceChangeStateAction.AddParameter("newState", EdmCoreModel.Instance.GetString(true));
            model.AddElement(FullyQualifiedNamespaceChangeStateAction);

            var FullyQualifiedNamespaceGetMyPersonFunction = new EdmFunction("Fully.Qualified.Namespace", "GetMyPerson", FullyQualifiedNamespacePersonTypeReference, true, null, false);
            FullyQualifiedNamespaceGetMyPersonFunction.AddParameter("dog", FullyQualifiedNamespaceDogTypeReference);
            model.AddElement(FullyQualifiedNamespaceGetMyPersonFunction);
            model.AddElement(FullyQualifiedNamespaceMoveAction);

            var FullyQualifiedNamespaceGetCoolPeopleAction = new EdmFunction("Fully.Qualified.Namespace", "GetCoolPeople", new EdmCollectionTypeReference(new EdmCollectionType(FullyQualifiedNamespacePersonTypeReference)), false, null, true /*isComposable*/);
            FullyQualifiedNamespaceGetCoolPeopleAction.AddParameter("id", EdmCoreModel.Instance.GetInt32(true));
            FullyQualifiedNamespaceGetCoolPeopleAction.AddParameter("limit", EdmCoreModel.Instance.GetInt32(true));
            model.AddElement(FullyQualifiedNamespaceGetCoolPeopleAction);

            var FullyQualifiedNamespaceGetHotPeopleAction = new EdmFunction("Fully.Qualified.Namespace", "GetHotPeople", new EdmCollectionTypeReference(new EdmCollectionType(FullyQualifiedNamespacePersonTypeReference)), true, new EdmPathExpression("person"), true /*isComposable*/);
            FullyQualifiedNamespaceGetHotPeopleAction.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            FullyQualifiedNamespaceGetHotPeopleAction.AddParameter("limit", EdmCoreModel.Instance.GetInt32(true));
            model.AddElement(FullyQualifiedNamespaceGetHotPeopleAction);

            var FullyQualifiedNamespaceGetCoolestPersonAction = new EdmFunction("Fully.Qualified.Namespace", "GetCoolestPerson", FullyQualifiedNamespacePersonTypeReference, false, null, true /*isComposable*/);
            model.AddElement(FullyQualifiedNamespaceGetCoolestPersonAction);

            var FullyQualifiedNamespaceGetCoolestPersonWithStyleAction = new EdmFunction("Fully.Qualified.Namespace", "GetCoolestPersonWithStyle", FullyQualifiedNamespacePersonTypeReference, false, null, true /*isComposable*/);
            FullyQualifiedNamespaceGetCoolestPersonWithStyleAction.AddParameter("styleID", EdmCoreModel.Instance.GetInt32(true));
            model.AddElement(FullyQualifiedNamespaceGetCoolestPersonWithStyleAction);

            var FullyQualifiedNamespaceGetBestManagerAction = new EdmFunction("Fully.Qualified.Namespace", "GetBestManager", FullyQualifiedNamespaceManagerTypeReference, false, null, true /*isComposable*/);
            model.AddElement(FullyQualifiedNamespaceGetBestManagerAction);

            var FullyQualifiedNamespaceGetNothingAction = new EdmAction("Fully.Qualified.Namespace", "GetNothing", null, false, null);
            model.AddElement(FullyQualifiedNamespaceGetNothingAction);

            var FullyQualifiedNamespaceGetSomeNumberAction = new EdmFunction("Fully.Qualified.Namespace", "GetSomeNumber", EdmCoreModel.Instance.GetInt32(true), false, null, true /*isComposable*/);
            model.AddElement(FullyQualifiedNamespaceGetSomeNumberAction);

            var FullyQualifiedNamespaceGetSomeAddressAction = new EdmFunction("Fully.Qualified.Namespace", "GetSomeAddress", FullyQualifiedNamespaceAddressTypeReference, false, null, true /*isComposable*/);
            model.AddElement(FullyQualifiedNamespaceGetSomeAddressAction);

            var FullyQualifiedNamespaceGetSomeNumbersAction = new EdmFunction("Fully.Qualified.Namespace", "GetSomeNumbers", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetInt32(true))), false, null, true /*isComposable*/);
            model.AddElement(FullyQualifiedNamespaceGetSomeNumbersAction);

            var FullyQualifiedNamespaceGetSomeColorsFunction = new EdmFunction("Fully.Qualified.Namespace", "GetSomeColors", new EdmCollectionTypeReference(new EdmCollectionType(colorTypeReference)), false, null, true /*isComposable*/);
            model.AddElement(FullyQualifiedNamespaceGetSomeColorsFunction);

            var FullyQualifiedNamespaceGetSomeColorFunction = new EdmFunction("Fully.Qualified.Namespace", "GetSomeColor", colorTypeReference, false, null, true /*isComposable*/);
            model.AddElement(FullyQualifiedNamespaceGetSomeColorFunction);

            var FullyQualifiedNamespaceGetSomeAddressesAction = new EdmFunction("Fully.Qualified.Namespace", "GetSomeAddresses", new EdmCollectionTypeReference(new EdmCollectionType(FullyQualifiedNamespaceAddressTypeReference)), false, null, true /*isComposable*/);
            model.AddElement(FullyQualifiedNamespaceGetSomeAddressesAction);

            var FullyQualifiedNamespaceResetAllDataAction = new EdmAction("Fully.Qualified.Namespace", "ResetAllData", null, false, null);
            model.AddElement(FullyQualifiedNamespaceResetAllDataAction);

            var FullyQualifiedNamespaceGetMostImporantPersonFunction = new EdmFunction("Fully.Qualified.Namespace", "GetMostImporantPerson", FullyQualifiedNamespacePersonTypeReference, false, null, false);
            model.AddElement(FullyQualifiedNamespaceGetMostImporantPersonFunction);

            var FullyQualifiedNamespaceGetMostImporantPersonFunction2 = new EdmFunction("Fully.Qualified.Namespace", "GetMostImporantPerson", FullyQualifiedNamespacePersonTypeReference, false, null, false);
            FullyQualifiedNamespaceGetMostImporantPersonFunction2.AddParameter("city", EdmCoreModel.Instance.GetString(true));
            model.AddElement(FullyQualifiedNamespaceGetMostImporantPersonFunction2);

            var FullyQualifiedNamespaceGetPriorNumbersFunction = new EdmFunction("Fully.Qualified.Namespace", "GetPriorNumbers", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetInt32(true))), true, null, true);
            FullyQualifiedNamespaceGetPriorNumbersFunction.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            model.AddElement(FullyQualifiedNamespaceGetPriorNumbersFunction);

            var FullyQualifiedNamespaceGetPriorAddressesFunction = new EdmFunction("Fully.Qualified.Namespace", "GetPriorAddresses", new EdmCollectionTypeReference(new EdmCollectionType(FullyQualifiedNamespaceAddressTypeReference)), true, null, true);
            FullyQualifiedNamespaceGetPriorAddressesFunction.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            model.AddElement(FullyQualifiedNamespaceGetPriorAddressesFunction);

            var FullyQualifiedNamespaceGetPriorAddressFunction = new EdmFunction("Fully.Qualified.Namespace", "GetPriorAddress", FullyQualifiedNamespaceAddressTypeReference, true, null, true);
            FullyQualifiedNamespaceGetPriorAddressFunction.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            model.AddElement(FullyQualifiedNamespaceGetPriorAddressFunction);

            var FullyQualifiedNamespaceGetFavoriteColorsFunction = new EdmFunction("Fully.Qualified.Namespace", "GetFavoriteColors", new EdmCollectionTypeReference(new EdmCollectionType(colorTypeReference)), true, null, true);
            FullyQualifiedNamespaceGetFavoriteColorsFunction.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            model.AddElement(FullyQualifiedNamespaceGetFavoriteColorsFunction);

            var FullyQualifiedNamespaceGetFavoriteColorFunction = new EdmFunction("Fully.Qualified.Namespace", "GetFavoriteColor", colorTypeReference, true, null, true);
            FullyQualifiedNamespaceGetFavoriteColorFunction.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            model.AddElement(FullyQualifiedNamespaceGetFavoriteColorFunction);

            var FullyQualifiedNamespaceGetNearbyPriorAddressesFunction = new EdmFunction("Fully.Qualified.Namespace", "GetNearbyPriorAddresses", new EdmCollectionTypeReference(new EdmCollectionType(FullyQualifiedNamespaceAddressTypeReference)), true, null, false);
            FullyQualifiedNamespaceGetNearbyPriorAddressesFunction.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            FullyQualifiedNamespaceGetNearbyPriorAddressesFunction.AddParameter("currentLocation", EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.GeographyPoint, true));
            FullyQualifiedNamespaceGetNearbyPriorAddressesFunction.AddParameter("limit", EdmCoreModel.Instance.GetInt32(true));
            model.AddElement(FullyQualifiedNamespaceGetNearbyPriorAddressesFunction);

            var FullyQualifiedNamespaceGetColorAtPositionFunction = new EdmFunction("Fully.Qualified.Namespace", "GetColorAtPosition", EdmCoreModel.Instance.GetString(true), true, null, false);
            FullyQualifiedNamespaceGetColorAtPositionFunction.AddParameter("painting", FullyQualifiedNamespacePaintingTypeReference);
            FullyQualifiedNamespaceGetColorAtPositionFunction.AddParameter("position", EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.GeometryPoint, true));
            FullyQualifiedNamespaceGetColorAtPositionFunction.AddParameter("includeAlpha", EdmCoreModel.Instance.GetBoolean(true));
            model.AddElement(FullyQualifiedNamespaceGetColorAtPositionFunction);

            var FullyQualifiedNamespaceMoveEveryoneAction = new EdmAction("Fully.Qualified.Namespace", "MoveEveryone", EdmCoreModel.Instance.GetBoolean(true), false, null);
            FullyQualifiedNamespaceMoveEveryoneAction.AddParameter("streetAddress", EdmCoreModel.Instance.GetString(true));
            model.AddElement(FullyQualifiedNamespaceMoveEveryoneAction);

            var FullyQualifiedNamespaceGetFullNameFunction = new EdmFunction("Fully.Qualified.Namespace", "GetFullName", FullyQualifiedNamespaceNameTypeReference, true, null, true);
            FullyQualifiedNamespaceGetNearbyPriorAddressesFunction.AddParameter("person", FullyQualifiedNamespacePersonTypeReference);
            FullyQualifiedNamespaceGetFullNameFunction.AddParameter("nickname", FullyQualifiedNamespaceNameTypeReference);
            model.AddElement(FullyQualifiedNamespaceGetFullNameFunction);

            #endregion

            #region Context Container

            var FullyQualifiedNamespaceContext = new EdmEntityContainer("Fully.Qualified.Namespace", "Context");
            model.AddElement(FullyQualifiedNamespaceContext);

            var FullyQualifiedNamespaceContextPeople = FullyQualifiedNamespaceContext.AddEntitySet("People", FullyQualifiedNamespacePerson);
            var FullyQualifiedNamespaceContextDogs = FullyQualifiedNamespaceContext.AddEntitySet("Dogs", FullyQualifiedNamespaceDog);
            var FullyQualifiedNamespaceContextLions = FullyQualifiedNamespaceContext.AddEntitySet("Lions", FullyQualifiedNamespaceLion);
            var FullyQualifiedNamespaceContextPaintings = FullyQualifiedNamespaceContext.AddEntitySet("Paintings", FullyQualifiedNamespacePainting);
            var FullyQualifiedNamespaceContextUsers = FullyQualifiedNamespaceContext.AddEntitySet("Users", FullyQualifiedNamespaceUserAccount);
            var FullyQualifiedNamespaceContextPet1Set = FullyQualifiedNamespaceContext.AddEntitySet("Pet1Set", FullyQualifiedNamespacePet1);
            var FullyQualifiedNamespaceContextPet2Set = FullyQualifiedNamespaceContext.AddEntitySet("Pet2Set", FullyQualifiedNamespacePet2);
            var FullyQualifiedNamespaceContextPet3Set = FullyQualifiedNamespaceContext.AddEntitySet("Pet3Set", FullyQualifiedNamespacePet3);
            var FullyQualifiedNamespaceContextPet4Set = FullyQualifiedNamespaceContext.AddEntitySet("Pet4Set", FullyQualifiedNamespacePet4);
            var FullyQualifiedNamespaceContextPet5Set = FullyQualifiedNamespaceContext.AddEntitySet("Pet5Set", FullyQualifiedNamespacePet5);
            var FullyQualifiedNamespaceContextPet6Set = FullyQualifiedNamespaceContext.AddEntitySet("Pet6Set", FullyQualifiedNamespacePet6);
            var FullyQualifiedNamespaceContextChimera = FullyQualifiedNamespaceContext.AddEntitySet("Chimeras", FullyQualifiedNamespaceChimera);

            FullyQualifiedNamespaceContextPeople.AddNavigationTarget(FullyQualifiedNamespacePerson_MyDog, FullyQualifiedNamespaceContextDogs);
            FullyQualifiedNamespaceContextPeople.AddNavigationTarget(FullyQualifiedNamespacePerson_MyRelatedDogs, FullyQualifiedNamespaceContextDogs);
            FullyQualifiedNamespaceContextPeople.AddNavigationTarget(FullyQualifiedNamespacePerson_MyLions, FullyQualifiedNamespaceContextLions);
            FullyQualifiedNamespaceContextPeople.AddNavigationTarget(FullyQualifiedNamespacePerson_MyPaintings, FullyQualifiedNamespaceContextPaintings);
            FullyQualifiedNamespaceContextPeople.AddNavigationTarget(FullyQualifiedNamespacePerson_MyFavoritePainting, FullyQualifiedNamespaceContextPaintings);
            FullyQualifiedNamespaceContextPeople.AddNavigationTarget(FullyQualifiedNamespaceEmployee_PaintingsInOffice, FullyQualifiedNamespaceContextPaintings);
            FullyQualifiedNamespaceContextPeople.AddNavigationTarget(FullyQualifiedNamespaceEmployee_Manager, FullyQualifiedNamespaceContextPeople);
            FullyQualifiedNamespaceContextPeople.AddNavigationTarget(FullyQualifiedNamespaceManager_DirectReports, FullyQualifiedNamespaceContextPeople);
            FullyQualifiedNamespaceContextPeople.AddNavigationTarget(FullyQualifiedNamespacePerson_MyPet2Set, FullyQualifiedNamespaceContextPet2Set);
            FullyQualifiedNamespaceContextDogs.AddNavigationTarget(FullyQualifiedNamespaceDog_MyPeople, FullyQualifiedNamespaceContextPeople);
            FullyQualifiedNamespaceContextDogs.AddNavigationTarget(FullyQualifiedNamespaceDog_FastestOwner, FullyQualifiedNamespaceContextPeople);
            FullyQualifiedNamespaceContextDogs.AddNavigationTarget(FullyQualifiedNamespaceDog_LionsISaw, FullyQualifiedNamespaceContextLions);
            FullyQualifiedNamespaceContextLions.AddNavigationTarget(FullyQualifiedNamespaceLion_Friends, FullyQualifiedNamespaceContextLions);
            FullyQualifiedNamespaceContextPaintings.AddNavigationTarget(FullyQualifiedNamespacePainting_Owner, FullyQualifiedNamespaceContextPeople);

            // Add singleton
            var FullQualifiedNamespaceSingletonBoss = FullyQualifiedNamespaceContext.AddSingleton("Boss", FullyQualifiedNamespacePerson);
            FullQualifiedNamespaceSingletonBoss.AddNavigationTarget(FullyQualifiedNamespacePerson_MyDog, FullyQualifiedNamespaceContextDogs);
            FullQualifiedNamespaceSingletonBoss.AddNavigationTarget(FullyQualifiedNamespacePerson_MyPaintings, FullyQualifiedNamespaceContextPaintings);
            FullyQualifiedNamespaceContext.AddFunctionImport("GetPet1", FullyQualifiedNamespaceGetPet1Function, new EdmEntitySetReferenceExpression(FullyQualifiedNamespaceContextPet1Set));
            FullyQualifiedNamespaceContext.AddFunctionImport("GetPet2", FullyQualifiedNamespaceGetPet2Function, new EdmEntitySetReferenceExpression(FullyQualifiedNamespaceContextPet2Set));
            FullyQualifiedNamespaceContext.AddFunctionImport("GetPet3", FullyQualifiedNamespaceGetPet3Function, new EdmEntitySetReferenceExpression(FullyQualifiedNamespaceContextPet3Set));
            FullyQualifiedNamespaceContext.AddFunctionImport("GetPet4", FullyQualifiedNamespaceGetPet4Function, new EdmEntitySetReferenceExpression(FullyQualifiedNamespaceContextPet4Set));
            FullyQualifiedNamespaceContext.AddFunctionImport("GetPet5", FullyQualifiedNamespaceGetPet5Function, new EdmEntitySetReferenceExpression(FullyQualifiedNamespaceContextPet5Set));
            FullyQualifiedNamespaceContext.AddFunctionImport("GetPet6", FullyQualifiedNamespaceGetPet6Function, new EdmEntitySetReferenceExpression(FullyQualifiedNamespaceContextPet6Set));
            FullyQualifiedNamespaceContext.AddFunctionImport("GetPetCount", FullyQualifiedNamespaceGetPetCountFunction, new EdmEntitySetReferenceExpression(FullyQualifiedNamespaceContextPet5Set));

            FullyQualifiedNamespaceContext.AddFunctionImport("FindMyOwner", FullyQualifiedNamespaceFindMyOwnerFunction, new EdmEntitySetReferenceExpression(model.FindEntityContainer("Fully.Qualified.Namespace.Context").FindEntitySet("People")));

            FullyQualifiedNamespaceContext.AddFunctionImport("IsAddressGood", FullyQualifiedNamespaceIsAddressGoodFunction, null);

            FullyQualifiedNamespaceContext.AddFunctionImport("GetCoolPeople", FullyQualifiedNamespaceGetCoolPeopleAction, new EdmEntitySetReferenceExpression(model.FindEntityContainer("Fully.Qualified.Namespace.Context").FindEntitySet("People")));

            FullyQualifiedNamespaceContext.AddFunctionImport("GetCoolestPerson", FullyQualifiedNamespaceGetCoolestPersonAction, new EdmEntitySetReferenceExpression(model.FindEntityContainer("Fully.Qualified.Namespace.Context").FindEntitySet("People")));

            FullyQualifiedNamespaceContext.AddFunctionImport("GetCoolestPersonWithStyle", FullyQualifiedNamespaceGetCoolestPersonWithStyleAction, new EdmEntitySetReferenceExpression(model.FindEntityContainer("Fully.Qualified.Namespace.Context").FindEntitySet("People")));

            FullyQualifiedNamespaceContext.AddFunctionImport("GetBestManager", FullyQualifiedNamespaceGetBestManagerAction, new EdmEntitySetReferenceExpression(model.FindEntityContainer("Fully.Qualified.Namespace.Context").FindEntitySet("People")));

            FullyQualifiedNamespaceContext.AddActionImport("GetNothing", FullyQualifiedNamespaceGetNothingAction);

            FullyQualifiedNamespaceContext.AddFunctionImport("GetSomeNumber", FullyQualifiedNamespaceGetSomeNumberAction);

            FullyQualifiedNamespaceContext.AddFunctionImport("GetSomeAddress", FullyQualifiedNamespaceGetSomeAddressAction);

            FullyQualifiedNamespaceContext.AddFunctionImport("GetSomeNumbers", FullyQualifiedNamespaceGetSomeNumbersAction);

            FullyQualifiedNamespaceContext.AddFunctionImport("GetSomeAddresses", FullyQualifiedNamespaceGetSomeAddressesAction);

            FullyQualifiedNamespaceContext.AddActionImport("ResetAllData", FullyQualifiedNamespaceResetAllDataAction);

            FullyQualifiedNamespaceContext.AddFunctionImport("GetMostImporantPerson", FullyQualifiedNamespaceGetMostImporantPersonFunction);

            FullyQualifiedNamespaceContext.AddFunctionImport("GetMostImporantPerson", FullyQualifiedNamespaceGetMostImporantPersonFunction2);

            FullyQualifiedNamespaceContext.AddActionImport("MoveEveryone", FullyQualifiedNamespaceMoveEveryoneAction);

            #endregion

            try
            {
                // serialize edm
                XDocument document = new XDocument();
                IEnumerable<EdmError> errors;
                using (var writer = document.CreateWriter())
                {
                    EdmxWriter.TryWriteEdmx(model, writer, EdmxTarget.OData, out errors).Should().BeTrue();
                }

                string doc = document.ToString();

                // deserialize edm xml
                // TODO: remove the above model building codes.
                IEdmModel parsedModel;
                if (EdmxReader.TryParse(XmlReader.Create(new StringReader(HardCodedTestModelXml.MainModelXml)), (Uri uri) =>
                {
                    if (string.Equals(uri.AbsoluteUri, "http://submodel1/"))
                    {
                        return XmlReader.Create(new StringReader(HardCodedTestModelXml.SubModelXml1));
                    }
                    else if (string.Equals(uri.AbsoluteUri, "http://submodel2/"))
                    {
                        return XmlReader.Create(new StringReader(HardCodedTestModelXml.SubModelXml2));
                    }
                    else if (string.Equals(uri.AbsoluteUri, "http://submodel3/"))
                    {
                        return XmlReader.Create(new StringReader(HardCodedTestModelXml.SubModelXml3));
                    }
                    else if (string.Equals(uri.AbsoluteUri, "http://submodel4/"))
                    {
                        return XmlReader.Create(new StringReader(HardCodedTestModelXml.SubModelXml4));
                    }

                    throw new Exception("edmx:refernece must have a valid url." + uri.AbsoluteUri);
                }, out parsedModel, out errors))
                {
                   return parsedModel;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return null;
        }
        private void BuildEdmModel()
        {
            _entityType = new EdmEntityTypeReference(new EdmEntityType("NS", "Entity"), isNullable: false);
            _derivedEntityType = new EdmEntityTypeReference(new EdmEntityType("NS", "DerivedEntity", _entityType.EntityDefinition()), isNullable: false);
            var entityCollection = new EdmCollectionTypeReference(new EdmCollectionType(_entityType));
            var derivedEntityCollection = new EdmCollectionTypeReference(new EdmCollectionType(_derivedEntityType));

            EdmModel model = new EdmModel();
            EdmEntityContainer container = new EdmEntityContainer("NS", "Name");
            model.AddElement(container);

            // non-bindable action
            container.AddActionImport(new EdmAction("NS", "NonBindableAction", returnType: null));

            // action bound to entity
            var actionBoundToEntity = new EdmAction(
                "NS",
                "ActionBoundToEntity",
                returnType: null,
                isBound: true,
                entitySetPathExpression: null);
            actionBoundToEntity.AddParameter("bindingParameter", _entityType);
            model.AddElement(actionBoundToEntity);

            // action bound to derived entity
            var actionBoundToDerivedEntity = new EdmAction(
                "NS",
                "ActionBoundToDerivedEntity",
                returnType: null,
                isBound: true,
                entitySetPathExpression: null);
            actionBoundToDerivedEntity.AddParameter("bindingParameter", _derivedEntityType);
            model.AddElement(actionBoundToDerivedEntity);

            // action bound to entity collection
            var actionBoundToEntityCollection = new EdmAction(
                "NS",
                "ActionBoundToEntityCollection",
                returnType: null,
                isBound: true,
                entitySetPathExpression: null);
            actionBoundToEntityCollection.AddParameter("bindingParameter", entityCollection);
            model.AddElement(actionBoundToEntityCollection);

            // action bound to derived entity collection
            var actionBoundToDerivedEntityCollection = new EdmAction(
                "NS",
                "ActionBoundToDerivedEntityCollection",
                returnType: null,
                isBound: true,
                entitySetPathExpression: null);
            actionBoundToDerivedEntityCollection.AddParameter("bindingParameter", derivedEntityCollection);
            model.AddElement(actionBoundToDerivedEntityCollection);

            // ambiguos actions
            container.AddActionImport(new EdmAction("NS", "AmbiguousAction", returnType: null));
            container.AddActionImport(new EdmAction("NS", "AmbiguousAction", returnType: null));

            IEdmTypeReference returnType = new EdmPrimitiveTypeReference(
                EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), false);

            // non-bindable function
            container.AddFunctionImport(new EdmFunction("NS", "NonBindableFunction", returnType));

            // function bound to entity
            var functionBoundToEntity = new EdmFunction(
                "NS",
                "FunctionBoundToEntity",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            functionBoundToEntity.AddParameter("bindingParameter", _entityType);
            model.AddElement(functionBoundToEntity);

            // function bound to entity
            var functionBoundToDerivedEntity = new EdmFunction(
                "NS",
                "FunctionBoundToDerivedEntity",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            functionBoundToDerivedEntity.AddParameter("bindingParameter", _derivedEntityType);
            model.AddElement(functionBoundToDerivedEntity);

            // function bound to entity collection
            var functionBoundToEntityCollection = new EdmFunction(
                "NS",
                "FunctionBoundToEntityCollection",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            functionBoundToEntityCollection.AddParameter("bindingParameter", entityCollection);
            model.AddElement(functionBoundToEntityCollection);

            // function bound to derived entity collection
            var functionBoundToDerivedEntityCollection = new EdmFunction(
                "NS",
                "FunctionBoundToDerivedEntityCollection",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            functionBoundToDerivedEntityCollection.AddParameter("bindingParameter", derivedEntityCollection);
            model.AddElement(functionBoundToDerivedEntityCollection);

            _model = model;
            _container = container;
        }
Exemple #14
0
        public static IEdmModel ModelWithAllConceptsEdm()
        {
            var stringType = EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String);

            var model = new EdmModel();
            var addressType = new EdmComplexType("NS1", "Address");
            addressType.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String);
            addressType.AddStructuralProperty("City", new EdmStringTypeReference(stringType, /*isNullable*/false, /*isUnbounded*/false, /*maxLength*/30, /*isUnicode*/true));
            model.AddElement(addressType);

            var zipCodeType = new EdmComplexType("NS1", "ZipCode");
            zipCodeType.AddStructuralProperty("Main", new EdmStringTypeReference(stringType, /*isNullable*/false, /*isUnbounded*/false, /*maxLength*/5, /*isUnicode*/false));
            zipCodeType.AddStructuralProperty("Extended", new EdmStringTypeReference(stringType, /*isNullable*/true, /*isUnbounded*/false, /*maxLength*/5, /*isUnicode*/false));
            model.AddElement(zipCodeType);
            addressType.AddStructuralProperty("Zip", new EdmComplexTypeReference(zipCodeType, false));

            var foreignAddressType = new EdmComplexType("NS1", "ForeignAddress", addressType, false);
            foreignAddressType.AddStructuralProperty("State", EdmPrimitiveTypeKind.String);
            model.AddElement(foreignAddressType);

            var personType = new EdmEntityType("NS1", "Person", null, true, false);
            personType.AddKeys(personType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, false));
            model.AddElement(personType);

            var customerType = new EdmEntityType("NS1", "Customer", personType);
            customerType.AddStructuralProperty("IsVIP", EdmPrimitiveTypeKind.Boolean);
            customerType.AddProperty(new EdmStructuralProperty(customerType, "LastUpdated", EdmCoreModel.Instance.GetDateTimeOffset(false), null, EdmConcurrencyMode.Fixed));
            customerType.AddStructuralProperty("BillingAddress", new EdmComplexTypeReference(addressType, false));
            customerType.AddStructuralProperty("ShippingAddress", new EdmComplexTypeReference(addressType, false));
            model.AddElement(customerType);

            var orderType = new EdmEntityType("NS1", "Order");
            orderType.AddKeys(orderType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, false));
            var customerIdProperty = orderType.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32, false);
            model.AddElement(orderType);

            var navProp1 = new EdmNavigationPropertyInfo { Name = "ToOrders", Target = orderType, TargetMultiplicity = EdmMultiplicity.Many, };
            var navProp2 = new EdmNavigationPropertyInfo { Name = "ToCustomer", Target = customerType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { customerIdProperty }, PrincipalProperties = customerType.Key() };
            customerType.AddBidirectionalNavigation(navProp1, navProp2);

            var container = new EdmEntityContainer("NS1", "MyContainer");
            container.AddEntitySet("PersonSet", personType);
            container.AddEntitySet("OrderSet", orderType);
            model.AddElement(container);

            var function = new EdmFunction("NS1", "Function1", EdmCoreModel.Instance.GetInt64(true));
            function.AddParameter("Param1", EdmCoreModel.Instance.GetInt32(true));
            container.AddFunctionImport(function);
            model.AddElement(function);

            return model;
        }
        public ODataJsonLightWriterShortSpanIntegrationTests()
        {
            EdmModel tmpModel = new EdmModel();

            EdmComplexType complexType = new EdmComplexType("NS", "MyComplexType");
            EdmComplexTypeReference complexTypeReference = new EdmComplexTypeReference(complexType, isNullable: true);
            complexType.AddProperty(new EdmStructuralProperty(complexType, "StringProperty", EdmCoreModel.Instance.GetString(isNullable: true)));
            complexType.AddProperty(new EdmStructuralProperty(complexType, "ComplexProperty", complexTypeReference));

            EdmComplexType derivedComplexType = new EdmComplexType("NS", "MyDerivedComplexType", complexType, false);
            derivedComplexType.AddProperty(new EdmStructuralProperty(derivedComplexType, "DerivedStringProperty", EdmCoreModel.Instance.GetString(isNullable: true)));
            
            this.entityType = new EdmEntityType("NS", "MyEntityType", isAbstract: false, isOpen: true, baseType: null);
            this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "StreamProperty", EdmCoreModel.Instance.GetStream(isNullable: true)));
            this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "StringProperty", EdmCoreModel.Instance.GetString(isNullable: true)));
            this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "ComplexProperty", complexTypeReference));
            EdmCollectionTypeReference stringCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(isNullable: false)));
            this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "PrimitiveCollectionProperty", stringCollectionType));
            EdmCollectionTypeReference nullableStringCollectionType = new EdmCollectionTypeReference(
                new EdmCollectionType(EdmCoreModel.Instance.GetString(isNullable: true)));
            this.entityType.AddProperty(new EdmStructuralProperty(
                this.entityType,
                "NullablePrimitiveCollectionProperty",
                nullableStringCollectionType));
            EdmCollectionTypeReference nullableIntCollectionType = new EdmCollectionTypeReference(
                new EdmCollectionType(EdmCoreModel.Instance.GetInt32(isNullable: true)));
            this.entityType.AddProperty(new EdmStructuralProperty(
                this.entityType,
                "NullableIntCollectionProperty",
                nullableIntCollectionType));
            EdmCollectionTypeReference complexCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(complexTypeReference));
            this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "ComplexCollectionProperty", complexCollectionType));

            this.entityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "EntityReferenceProperty", Target = this.entityType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne });
            this.entityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "EntitySetReferenceProperty", Target = this.entityType, TargetMultiplicity = EdmMultiplicity.Many });

            this.derivedEntityType = new EdmEntityType("NS", "MyDerivedEntityType", isAbstract: false, isOpen: true, baseType: this.entityType);
            this.mleEntityType = new EdmEntityType("NS", "MyMleEntityType", isAbstract: false, isOpen: true, hasStream: true, baseType: this.derivedEntityType);

            tmpModel.AddElement(this.entityType);
            tmpModel.AddElement(this.derivedEntityType);
            tmpModel.AddElement(this.mleEntityType);
            tmpModel.AddElement(complexType);
            tmpModel.AddElement(derivedComplexType);

            var defaultContainer = new EdmEntityContainer("NS", "DefaultContainer_sub");
            tmpModel.AddElement(defaultContainer);

            this.entitySet = new EdmEntitySet(defaultContainer, "MySet", this.entityType);

            var entityTypeReference = new EdmEntityTypeReference(this.entityType, isNullable: false);

            EdmAction action = new EdmAction("NS", "Action1", null /*returnType*/, true /*isBound*/, null /*entitySetPath*/);
            action.AddParameter( "bindingParameter", entityTypeReference);
            tmpModel.AddElement(action);
            defaultContainer.AddActionImport("Action1", action);
            
            EdmFunction function = new EdmFunction("NS", "Action1", EdmCoreModel.Instance.GetInt32(true) /*returnType*/, true /*isBound*/, null /*entitySetPath*/, false /*isComposable*/);
            function.AddParameter("bindingParameter", entityTypeReference);
            tmpModel.AddElement(function);
            defaultContainer.AddFunctionImport("Function1", function);

            this.userModel = TestUtils.WrapReferencedModelsToMainModel("NS", "DefaultContainer", tmpModel);
        }
 public void GetTargetEntitySetForFunctionWithStaticSet()
 {
     var model = new EdmModel();
     var container = new EdmEntityContainer("Fake", "Container");
     model.AddElement(container);
     var entitySet = container.AddEntitySet("EntitySet", new EdmEntityType("Fake", "EntityType"));
     var function = new EdmFunction("Fake", "FakeFunction", new EdmEntityTypeReference(entitySet.EntityType(), false));
     var operationImport = container.AddFunctionImport("FakeAction", function, new EdmEntitySetReferenceExpression(entitySet));
     operationImport.GetTargetEntitySet(null, model).Should().BeSameAs(entitySet);
 }
        private static IEdmModel CreateModel()
        {
            var model = new EdmModel();

            var orderType = new EdmEntityType("Default", "Order");
            orderType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32);
            model.AddElement(orderType);

            var customerType = new EdmEntityType("Default", "Customer");
            customerType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32);
            model.AddElement(customerType);

            // Add navigations
            orderType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Customer",
                Target = customerType, TargetMultiplicity = EdmMultiplicity.One });

            var container = new EdmEntityContainer("Default", "Container");
            var orderSet = container.AddEntitySet("Orders", orderType);
            var customerSet = container.AddEntitySet("Customers", customerType);

            container.AddFunctionImport(
                new EdmFunction(
                    "Default",
                    "GetIDs",
                    new EdmCollectionTypeReference(
                        new EdmCollectionType(
                            new EdmPrimitiveTypeReference(
                                EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32),
                                isNullable: false)))));

            orderSet.AddNavigationTarget(orderType.NavigationProperties().Single(np => np.Name == "Customer"),
                customerSet);

            model.AddElement(container);
            return model;
        }
        private static void UnboundFunction(EdmEntityContainer container, string funcName, string paramName, IEdmTypeReference edmType)
        {
            IEdmTypeReference returnType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);

            var unboundFunction = new EdmFunction("NS", funcName, returnType, isBound: false, entitySetPathExpression: null, isComposable: true);
            unboundFunction.AddParameter("key", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: false));
            unboundFunction.AddParameter(paramName, edmType);
            container.AddFunctionImport(funcName, unboundFunction, entitySet: null);
        }
        public static IEdmModel CreateODataServiceModel(string ns)
        {
            EdmModel model = new EdmModel();
            var defaultContainer = new EdmEntityContainer(ns, "InMemoryEntities");
            model.AddElement(defaultContainer);

            #region ComplexType
            var addressType = new EdmComplexType(ns, "Address");
            addressType.AddProperty(new EdmStructuralProperty(addressType, "Street", EdmCoreModel.Instance.GetString(false)));
            addressType.AddProperty(new EdmStructuralProperty(addressType, "City", EdmCoreModel.Instance.GetString(false)));
            addressType.AddProperty(new EdmStructuralProperty(addressType, "PostalCode", EdmCoreModel.Instance.GetString(false)));
            model.AddElement(addressType);

            var homeAddressType = new EdmComplexType(ns, "HomeAddress", addressType, false);
            homeAddressType.AddProperty(new EdmStructuralProperty(homeAddressType, "FamilyName", EdmCoreModel.Instance.GetString(true)));
            model.AddElement(homeAddressType);

            var companyAddressType = new EdmComplexType(ns, "CompanyAddress", addressType, false);
            companyAddressType.AddProperty(new EdmStructuralProperty(companyAddressType, "CompanyName", EdmCoreModel.Instance.GetString(false)));
            model.AddElement(companyAddressType);

            var cityInformationType = new EdmComplexType(ns, "CityInformation");
            cityInformationType.AddProperty(new EdmStructuralProperty(cityInformationType, "CountryRegion", EdmCoreModel.Instance.GetString(false)));
            cityInformationType.AddProperty(new EdmStructuralProperty(cityInformationType, "IsCapital", EdmCoreModel.Instance.GetBoolean(false)));
            model.AddElement(cityInformationType);
            #endregion

            #region EnumType
            var accessLevelType = new EdmEnumType(ns, "AccessLevel", isFlags: true);
            accessLevelType.AddMember("None", new EdmIntegerConstant(0));
            accessLevelType.AddMember("Read", new EdmIntegerConstant(1));
            accessLevelType.AddMember("Write", new EdmIntegerConstant(2));
            accessLevelType.AddMember("Execute", new EdmIntegerConstant(4));
            accessLevelType.AddMember("ReadWrite", new EdmIntegerConstant(3));
            model.AddElement(accessLevelType);

            var colorType = new EdmEnumType(ns, "Color", isFlags: false);
            colorType.AddMember("Red", new EdmIntegerConstant(1));
            colorType.AddMember("Green", new EdmIntegerConstant(2));
            colorType.AddMember("Blue", new EdmIntegerConstant(4));
            model.AddElement(colorType);

            var companyCategory = new EdmEnumType(ns, "CompanyCategory", isFlags: false);
            companyCategory.AddMember("IT", new EdmIntegerConstant(0));
            companyCategory.AddMember("Communication", new EdmIntegerConstant(1));
            companyCategory.AddMember("Electronics", new EdmIntegerConstant(2));
            companyCategory.AddMember("Others", new EdmIntegerConstant(4));
            model.AddElement(companyCategory);
            #endregion

            #region Term
            model.AddElement(new EdmTerm(ns, "IsBoss", EdmCoreModel.Instance.GetBoolean(true), "Entity"));
            model.AddElement(new EdmTerm(ns, "AddressType", EdmCoreModel.Instance.GetString(true)));
            model.AddElement(new EdmTerm(ns, "CityInfo", new EdmComplexTypeReference(cityInformationType, false)));
            model.AddElement(new EdmTerm(ns, "DisplayName", EdmCoreModel.Instance.GetString(true)));
            #endregion

            var personType = new EdmEntityType(ns, "Person");
            var personIdProperty = new EdmStructuralProperty(personType, "PersonID", EdmCoreModel.Instance.GetInt32(false));
            personType.AddProperty(personIdProperty);
            personType.AddKeys(new IEdmStructuralProperty[] { personIdProperty });
            personType.AddProperty(new EdmStructuralProperty(personType, "FirstName", EdmCoreModel.Instance.GetString(false)));
            personType.AddProperty(new EdmStructuralProperty(personType, "LastName", EdmCoreModel.Instance.GetString(false)));
            personType.AddProperty(new EdmStructuralProperty(personType, "MiddleName", EdmCoreModel.Instance.GetString(true)));
            personType.AddProperty(new EdmStructuralProperty(personType, "HomeAddress", new EdmComplexTypeReference(addressType, true)));
            personType.AddProperty(new EdmStructuralProperty(personType, "Home", EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.GeographyPoint, true)));
            personType.AddProperty(new EdmStructuralProperty(personType, "Numbers", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false)))));
            personType.AddProperty(new EdmStructuralProperty(personType, "Emails", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(true)))));

            model.AddElement(personType);
            var personSet = new EdmEntitySet(defaultContainer, "People", personType);
            defaultContainer.AddElement(personSet);
            var boss = new EdmSingleton(defaultContainer, "Boss", personType);
            defaultContainer.AddElement(boss);

            var customerType = new EdmEntityType(ns, "Customer", personType);
            customerType.AddProperty(new EdmStructuralProperty(customerType, "City", EdmCoreModel.Instance.GetString(false)));
            customerType.AddProperty(new EdmStructuralProperty(customerType, "Birthday", EdmCoreModel.Instance.GetDateTimeOffset(false)));
            customerType.AddProperty(new EdmStructuralProperty(customerType, "TimeBetweenLastTwoOrders", EdmCoreModel.Instance.GetDuration(false)));
            model.AddElement(customerType);
            var customerSet = new EdmEntitySet(defaultContainer, "Customers", customerType);
            defaultContainer.AddElement(customerSet);

            EdmSingleton vipCustomer = new EdmSingleton(defaultContainer, "VipCustomer", customerType);
            defaultContainer.AddElement(vipCustomer);

            var employeeType = new EdmEntityType(ns, "Employee", personType);
            employeeType.AddProperty(new EdmStructuralProperty(employeeType, "DateHired", EdmCoreModel.Instance.GetDateTimeOffset(false)));
            employeeType.AddProperty(new EdmStructuralProperty(employeeType, "Office", EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.GeographyPoint, true)));
            model.AddElement(employeeType);
            var employeeSet = new EdmEntitySet(defaultContainer, "Employees", employeeType);
            defaultContainer.AddElement(employeeSet);

            var productType = new EdmEntityType(ns, "Product");
            var productIdProperty = new EdmStructuralProperty(productType, "ProductID", EdmCoreModel.Instance.GetInt32(false));
            productType.AddProperty(productIdProperty);
            productType.AddKeys(productIdProperty);
            productType.AddProperty(new EdmStructuralProperty(productType, "Name", EdmCoreModel.Instance.GetString(false)));
            productType.AddProperty(new EdmStructuralProperty(productType, "QuantityPerUnit", EdmCoreModel.Instance.GetString(false)));
            productType.AddProperty(new EdmStructuralProperty(productType, "UnitPrice", EdmCoreModel.Instance.GetSingle(false)));
            productType.AddProperty(new EdmStructuralProperty(productType, "QuantityInStock", EdmCoreModel.Instance.GetInt32(false)));
            productType.AddProperty(new EdmStructuralProperty(productType, "Discontinued", EdmCoreModel.Instance.GetBoolean(false)));
            productType.AddProperty(new EdmStructuralProperty(productType, "UserAccess", new EdmEnumTypeReference(accessLevelType, true)));
            productType.AddProperty(new EdmStructuralProperty(productType, "SkinColor", new EdmEnumTypeReference(colorType, true)));
            productType.AddProperty(new EdmStructuralProperty(productType, "CoverColors", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEnumTypeReference(colorType, false)))));
            model.AddElement(productType);
            var productSet = new EdmEntitySet(defaultContainer, "Products", productType);
            defaultContainer.AddElement(productSet);

            var productDetailType = new EdmEntityType(ns, "ProductDetail");
            var productDetailIdProperty1 = new EdmStructuralProperty(productDetailType, "ProductID", EdmCoreModel.Instance.GetInt32(false));
            var productDetailIdProperty2 = new EdmStructuralProperty(productDetailType, "ProductDetailID", EdmCoreModel.Instance.GetInt32(false));
            productDetailType.AddProperty(productDetailIdProperty1);
            productDetailType.AddKeys(productDetailIdProperty1);
            productDetailType.AddProperty(productDetailIdProperty2);
            productDetailType.AddKeys(productDetailIdProperty2);
            productDetailType.AddProperty(new EdmStructuralProperty(productDetailType, "ProductName", EdmCoreModel.Instance.GetString(false)));
            productDetailType.AddProperty(new EdmStructuralProperty(productDetailType, "Description", EdmCoreModel.Instance.GetString(false)));
            model.AddElement(productDetailType);
            var productDetailSet = new EdmEntitySet(defaultContainer, "ProductDetails", productDetailType);
            defaultContainer.AddElement(productDetailSet);

            var productReviewType = new EdmEntityType(ns, "ProductReview");
            var productReviewIdProperty1 = new EdmStructuralProperty(productReviewType, "ProductID", EdmCoreModel.Instance.GetInt32(false));
            var productReviewIdProperty2 = new EdmStructuralProperty(productReviewType, "ProductDetailID", EdmCoreModel.Instance.GetInt32(false));
            var productReviewIdProperty3 = new EdmStructuralProperty(productReviewType, "ReviewTitle", EdmCoreModel.Instance.GetString(false));
            var productReviewIdProperty4 = new EdmStructuralProperty(productReviewType, "RevisionID", EdmCoreModel.Instance.GetInt32(false));
            productReviewType.AddProperty(productReviewIdProperty1);
            productReviewType.AddKeys(productReviewIdProperty1);
            productReviewType.AddProperty(productReviewIdProperty2);
            productReviewType.AddKeys(productReviewIdProperty2);
            productReviewType.AddProperty(productReviewIdProperty3);
            productReviewType.AddKeys(productReviewIdProperty3);
            productReviewType.AddProperty(productReviewIdProperty4);
            productReviewType.AddKeys(productReviewIdProperty4);
            productReviewType.AddProperty(new EdmStructuralProperty(productReviewType, "Comment", EdmCoreModel.Instance.GetString(false)));
            productReviewType.AddProperty(new EdmStructuralProperty(productReviewType, "Author", EdmCoreModel.Instance.GetString(false)));
            model.AddElement(productReviewType);
            var productReviewSet = new EdmEntitySet(defaultContainer, "ProductReviews", productReviewType);
            defaultContainer.AddElement(productReviewSet);

            var abstractType = new EdmEntityType(ns, "AbstractEntity", null, true, false);
            model.AddElement(abstractType);

            var orderType = new EdmEntityType(ns, "Order", abstractType);
            var orderIdProperty = new EdmStructuralProperty(orderType, "OrderID", EdmCoreModel.Instance.GetInt32(false));
            orderType.AddProperty(orderIdProperty);
            orderType.AddKeys(orderIdProperty);
            orderType.AddProperty(new EdmStructuralProperty(orderType, "OrderDate", EdmCoreModel.Instance.GetDateTimeOffset(false)));
            orderType.AddProperty(new EdmStructuralProperty(orderType, "ShelfLife", EdmCoreModel.Instance.GetDuration(true)));
            orderType.AddProperty(new EdmStructuralProperty(orderType, "OrderShelfLifes", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetDuration(true)))));
            orderType.AddProperty(new EdmStructuralProperty(orderType, "ShipDate", EdmCoreModel.Instance.GetDate(false)));
            orderType.AddProperty(new EdmStructuralProperty(orderType, "ShipTime", EdmCoreModel.Instance.GetTimeOfDay(false)));

            model.AddElement(orderType);
            var orderSet = new EdmEntitySet(defaultContainer, "Orders", orderType);
            defaultContainer.AddElement(orderSet);

            var orderDetailType = new EdmEntityType(ns, "OrderDetail", abstractType);
            var orderId = new EdmStructuralProperty(orderDetailType, "OrderID", EdmCoreModel.Instance.GetInt32(false));
            orderDetailType.AddProperty(orderId);
            orderDetailType.AddKeys(orderId);
            var productId = new EdmStructuralProperty(orderDetailType, "ProductID", EdmCoreModel.Instance.GetInt32(false));
            orderDetailType.AddProperty(productId);
            orderDetailType.AddKeys(productId);
            orderDetailType.AddProperty(new EdmStructuralProperty(orderDetailType, "OrderPlaced", EdmCoreModel.Instance.GetDateTimeOffset(false)));
            orderDetailType.AddProperty(new EdmStructuralProperty(orderDetailType, "Quantity", EdmCoreModel.Instance.GetInt32(false)));
            orderDetailType.AddProperty(new EdmStructuralProperty(orderDetailType, "UnitPrice", EdmCoreModel.Instance.GetSingle(false)));

            model.AddElement(orderDetailType);
            var orderDetailSet = new EdmEntitySet(defaultContainer, "OrderDetails", orderDetailType);
            defaultContainer.AddElement(orderDetailSet);

            var parentNavigation = personType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name = "Parent",
                Target = personType,
                TargetMultiplicity = EdmMultiplicity.One
            });
            var productOrderedNavigation = orderDetailType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name = "ProductOrdered",
                Target = productType,
                TargetMultiplicity = EdmMultiplicity.Many
            });

            var associatedOrderNavigation = orderDetailType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name = "AssociatedOrder",
                Target = orderType,
                TargetMultiplicity = EdmMultiplicity.One
            });
            var loggedInEmployeeNavigation = orderType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name = "LoggedInEmployee",
                Target = employeeType,
                TargetMultiplicity = EdmMultiplicity.One
            });
            var customerForOrderNavigation = orderType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name = "CustomerForOrder",
                Target = customerType,
                TargetMultiplicity = EdmMultiplicity.One
            });
            var orderDetailsNavigation = orderType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name = "OrderDetails",
                Target = orderDetailType,
                TargetMultiplicity = EdmMultiplicity.Many
            });
            var ordersNavigation = customerType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name = "Orders",
                Target = orderType,
                TargetMultiplicity = EdmMultiplicity.Many
            });
            var productProductDetailNavigation = productType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name = "Details",
                TargetMultiplicity = EdmMultiplicity.Many,
                Target = productDetailType,
                DependentProperties = new List<IEdmStructuralProperty>()
                    {
                        productIdProperty
                    },
                PrincipalProperties = new List<IEdmStructuralProperty>()
                    {
                        productDetailIdProperty1
                    }
            });
            var productDetailProductNavigation = productDetailType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name = "RelatedProduct",
                Target = productType,
                TargetMultiplicity = EdmMultiplicity.ZeroOrOne
            });
            var productDetailProductReviewNavigation = productDetailType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name = "Reviews",
                TargetMultiplicity = EdmMultiplicity.Many,
                Target = productReviewType,
                DependentProperties = new List<IEdmStructuralProperty>()
                    {
                        productDetailIdProperty1, 
                        productDetailIdProperty2,
                    },
                PrincipalProperties = new List<IEdmStructuralProperty>()
                    {
                        productReviewIdProperty1, 
                        productReviewIdProperty2
                    }
            });

            model.SetCoreChangeTrackingAnnotation(orderSet, new EdmStructuralProperty[] { orderIdProperty }, new EdmNavigationProperty[] { orderDetailsNavigation });

            ((EdmEntitySet)personSet).AddNavigationTarget(parentNavigation, personSet);
            ((EdmEntitySet)orderDetailSet).AddNavigationTarget(associatedOrderNavigation, orderSet);
            ((EdmEntitySet)orderDetailSet).AddNavigationTarget(productOrderedNavigation, productSet);
            ((EdmEntitySet)customerSet).AddNavigationTarget(ordersNavigation, orderSet);
            ((EdmEntitySet)customerSet).AddNavigationTarget(parentNavigation, personSet);
            ((EdmEntitySet)employeeSet).AddNavigationTarget(parentNavigation, personSet);
            ((EdmEntitySet)orderSet).AddNavigationTarget(loggedInEmployeeNavigation, employeeSet);
            ((EdmEntitySet)orderSet).AddNavigationTarget(customerForOrderNavigation, customerSet);
            ((EdmEntitySet)orderSet).AddNavigationTarget(orderDetailsNavigation, orderDetailSet);
            ((EdmEntitySet)productSet).AddNavigationTarget(productProductDetailNavigation, productDetailSet);
            ((EdmEntitySet)productDetailSet).AddNavigationTarget(productDetailProductNavigation, productSet);
            ((EdmEntitySet)productDetailSet).AddNavigationTarget(productDetailProductReviewNavigation, productReviewSet);

            #region Singleton

            var departmentType = new EdmEntityType(ns, "Department", null);
            var departmentId = new EdmStructuralProperty(departmentType, "DepartmentID", EdmCoreModel.Instance.GetInt32(false));
            departmentType.AddProperty(departmentId);
            departmentType.AddKeys(departmentId);
            departmentType.AddProperty(new EdmStructuralProperty(departmentType, "Name", EdmCoreModel.Instance.GetString(false)));
            departmentType.AddProperty(new EdmStructuralProperty(departmentType, "DepartmentNO", EdmCoreModel.Instance.GetString(true)));
            model.AddElement(departmentType);
            EdmEntitySet departments = new EdmEntitySet(defaultContainer, "Departments", departmentType);
            defaultContainer.AddElement(departments);

            var companyType = new EdmEntityType(ns, "Company", /*baseType*/ null, /*isAbstract*/ false, /*isOpen*/ true);
            var companyId = new EdmStructuralProperty(companyType, "CompanyID", EdmCoreModel.Instance.GetInt32(false));
            companyType.AddProperty(companyId);
            companyType.AddKeys(companyId);
            companyType.AddProperty(new EdmStructuralProperty(companyType, "CompanyCategory", new EdmEnumTypeReference(companyCategory, true)));
            companyType.AddProperty(new EdmStructuralProperty(companyType, "Revenue", EdmCoreModel.Instance.GetInt64(false)));
            companyType.AddProperty(new EdmStructuralProperty(companyType, "Name", EdmCoreModel.Instance.GetString(true)));
            companyType.AddProperty(new EdmStructuralProperty(companyType, "Address", new EdmComplexTypeReference(addressType, true)));

            model.AddElement(companyType);
            EdmSingleton company = new EdmSingleton(defaultContainer, "Company", companyType);
            defaultContainer.AddElement(company);

            var publicCompanyType = new EdmEntityType(ns, "PublicCompany", /*baseType*/ companyType, /*isAbstract*/ false, /*isOpen*/ true);
            publicCompanyType.AddProperty(new EdmStructuralProperty(publicCompanyType, "StockExchange", EdmCoreModel.Instance.GetString(true)));
            model.AddElement(publicCompanyType);
            EdmSingleton publicCompany = new EdmSingleton(defaultContainer, "PublicCompany", companyType);
            defaultContainer.AddElement(publicCompany);

            var assetType = new EdmEntityType(ns, "Asset", /*baseType*/ null, /*isAbstract*/ false, /*isOpen*/ false);
            var assetId = new EdmStructuralProperty(assetType, "AssetID", EdmCoreModel.Instance.GetInt32(false));
            assetType.AddProperty(assetId);
            assetType.AddKeys(assetId);
            assetType.AddProperty(new EdmStructuralProperty(assetType, "Name", EdmCoreModel.Instance.GetString(true)));
            assetType.AddProperty(new EdmStructuralProperty(assetType, "Number", EdmCoreModel.Instance.GetInt32(false)));
            model.AddElement(assetType);

            var clubType = new EdmEntityType(ns, "Club", /*baseType*/ null, /*isAbstract*/ false, /*isOpen*/ false);
            var clubId = new EdmStructuralProperty(clubType, "ClubID", EdmCoreModel.Instance.GetInt32(false));
            clubType.AddProperty(clubId);
            clubType.AddKeys(clubId);
            clubType.AddProperty(new EdmStructuralProperty(clubType, "Name", EdmCoreModel.Instance.GetString(true)));
            model.AddElement(clubType);

            var labourUnionType = new EdmEntityType(ns, "LabourUnion", /*baseType*/ null, /*isAbstract*/ false, /*isOpen*/ false);
            var labourUnionId = new EdmStructuralProperty(labourUnionType, "LabourUnionID", EdmCoreModel.Instance.GetInt32(false));
            labourUnionType.AddProperty(labourUnionId);
            labourUnionType.AddKeys(labourUnionId);
            labourUnionType.AddProperty(new EdmStructuralProperty(labourUnionType, "Name", EdmCoreModel.Instance.GetString(true)));
            model.AddElement(labourUnionType);
            EdmSingleton labourUnion = new EdmSingleton(defaultContainer, "LabourUnion", labourUnionType);
            defaultContainer.AddElement(labourUnion);

            var companyEmployeeNavigation = companyType.AddBidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "Employees",
                Target = employeeType,
                TargetMultiplicity = EdmMultiplicity.Many
            }, new EdmNavigationPropertyInfo()
            {
                Name = "Company",
                Target = companyType,
                TargetMultiplicity = EdmMultiplicity.One
            });

            var companyCustomerNavigation = companyType.AddBidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "VipCustomer",
                Target = customerType,
                TargetMultiplicity = EdmMultiplicity.One
            }, new EdmNavigationPropertyInfo()
            {
                Name = "Company",
                Target = companyType,
                TargetMultiplicity = EdmMultiplicity.One
            });

            var companyDepartmentsNavigation = companyType.AddBidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "Departments",
                Target = departmentType,
                TargetMultiplicity = EdmMultiplicity.Many
            },
            new EdmNavigationPropertyInfo()
            {
                Name = "Company",
                Target = companyType,
                TargetMultiplicity = EdmMultiplicity.One
            });

            var companyCoreDepartmentNavigation = companyType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "CoreDepartment",
                Target = departmentType,
                TargetMultiplicity = EdmMultiplicity.One
            });

            var publicCompanyAssetNavigation = publicCompanyType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name = "Assets",
                Target = assetType,
                TargetMultiplicity = EdmMultiplicity.Many,
                ContainsTarget = true
            });

            var publicCompanyClubNavigation = publicCompanyType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "Club",
                Target = clubType,
                TargetMultiplicity = EdmMultiplicity.One,
                ContainsTarget = true
            });

            var publicCompanyLabourUnionNavigation = publicCompanyType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "LabourUnion",
                Target = labourUnionType,
                TargetMultiplicity = EdmMultiplicity.One
            });

            //vipCustomer->orders
            ((EdmSingleton)vipCustomer).AddNavigationTarget(ordersNavigation, orderSet);
            //vipCustomer->people
            ((EdmSingleton)vipCustomer).AddNavigationTarget(parentNavigation, personSet);
            ((EdmSingleton)boss).AddNavigationTarget(parentNavigation, personSet);
            //employeeSet<->company
            ((EdmSingleton)company).AddNavigationTarget(companyEmployeeNavigation, employeeSet);
            ((EdmEntitySet)employeeSet).AddNavigationTarget(companyEmployeeNavigation.Partner, company);
            //company<->vipcustomer
            ((EdmSingleton)company).AddNavigationTarget(companyCustomerNavigation, vipCustomer);
            ((EdmSingleton)vipCustomer).AddNavigationTarget(companyCustomerNavigation.Partner, company);
            //company<->departments
            ((EdmSingleton)company).AddNavigationTarget(companyDepartmentsNavigation, departments);
            ((EdmEntitySet)departments).AddNavigationTarget(companyDepartmentsNavigation.Partner, company);
            //company<-> Single department
            ((EdmSingleton)company).AddNavigationTarget(companyCoreDepartmentNavigation, departments);
            //publicCompany<-> Singleton
            ((EdmSingleton)publicCompany).AddNavigationTarget(publicCompanyLabourUnionNavigation, labourUnion);

            #region Action/Function
            //Bound Action : bound to Entity, return EnumType
            var productAddAccessRightAction = new EdmAction(ns, "AddAccessRight", new EdmEnumTypeReference(accessLevelType, true), true, null);
            productAddAccessRightAction.AddParameter("product", new EdmEntityTypeReference(productType, false));
            productAddAccessRightAction.AddParameter("accessRight", new EdmEnumTypeReference(accessLevelType, true));
            model.AddElement(productAddAccessRightAction);

            //Bound Action : Bound to Singleton, Primitive Parameter return Primitive Type
            EdmAction increaseRevenue = new EdmAction(ns, "IncreaseRevenue", EdmCoreModel.Instance.GetInt64(false), /*isBound*/true, /*entitySetPathExpression*/null);
            increaseRevenue.AddParameter(new EdmOperationParameter(increaseRevenue, "p", new EdmEntityTypeReference(companyType, false)));
            increaseRevenue.AddParameter(new EdmOperationParameter(increaseRevenue, "IncreaseValue", EdmCoreModel.Instance.GetInt64(true)));
            model.AddElement(increaseRevenue);

            //Bound Action : Bound to Entity, Collection Of ComplexType Parameter, Return Entity
            var resetAddressAction = new EdmAction(ns, "ResetAddress", new EdmEntityTypeReference(personType, false), true, new EdmPathExpression("person"));
            resetAddressAction.AddParameter("person", new EdmEntityTypeReference(personType, false));
            resetAddressAction.AddParameter("addresses", new EdmCollectionTypeReference(new EdmCollectionType(new EdmComplexTypeReference(addressType, true))));
            resetAddressAction.AddParameter("index", EdmCoreModel.Instance.GetInt32(false));
            model.AddElement(resetAddressAction);

            //Bound Action : Bound to Entity, EntityType Parameter, Return Entity
            var placeOrderAction = new EdmAction(ns, "PlaceOrder", new EdmEntityTypeReference(orderType, false), true, new EdmPathExpression("customer/Orders"));
            placeOrderAction.AddParameter("customer", new EdmEntityTypeReference(customerType, false));
            placeOrderAction.AddParameter("order", new EdmEntityTypeReference(orderType, false));
            model.AddElement(placeOrderAction);

            //Bound Action : Bound to Entity, Collection Of EntityType Parameter, Return Collection of Entity
            var placeOrdersAction = new EdmAction(ns, "PlaceOrders", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(orderType, false))), true, new EdmPathExpression("customer/Orders"));
            placeOrdersAction.AddParameter("customer", new EdmEntityTypeReference(customerType, false));
            placeOrdersAction.AddParameter("orders", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(orderType, false))));
            model.AddElement(placeOrdersAction);

            //Bound Action : Bound to collection of EntitySet, Return Collection of Entity
            var discountSeveralProductAction = new EdmAction(ns, "Discount",
                new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(productType, false))), true, new EdmPathExpression("products"));
            discountSeveralProductAction.AddParameter("products", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(productType, false))));
            discountSeveralProductAction.AddParameter("percentage", EdmCoreModel.Instance.GetInt32(false));
            model.AddElement(discountSeveralProductAction);

            //Bound Action : Bound to Entity, return void
            var changeLabourUnionNameAction = new EdmAction(ns, "ChangeLabourUnionName", null, true, null);
            changeLabourUnionNameAction.AddParameter("labourUnion", new EdmEntityTypeReference(labourUnionType, false));
            changeLabourUnionNameAction.AddParameter("name", EdmCoreModel.Instance.GetString(true));
            model.AddElement(changeLabourUnionNameAction);

            //Bound Action : Bound to Entity, return order take Date/TimeOfDay as Parameter
            var changeShipTimeAndDate = new EdmAction(ns, "ChangeShipTimeAndDate", new EdmEntityTypeReference(orderType, false), true, new EdmPathExpression("order"));
            changeShipTimeAndDate.AddParameter("order", new EdmEntityTypeReference(orderType, false));
            changeShipTimeAndDate.AddParameter("date", EdmCoreModel.Instance.GetDate(false));
            changeShipTimeAndDate.AddParameter("time", EdmCoreModel.Instance.GetTimeOfDay(false));
            model.AddElement(changeShipTimeAndDate);

            //UnBound Action : Primitive parameter, Return void
            var discountAction = new EdmAction(ns, "Discount", null, false, null);
            discountAction.AddParameter("percentage", EdmCoreModel.Instance.GetInt32(false));
            model.AddElement(discountAction);
            defaultContainer.AddActionImport(discountAction);

            //UnBound Action : Collection of Primitive parameter, Return Collection of Primitive
            var resetBossEmailAction = new EdmAction(ns, "ResetBossEmail", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false))), false, null);
            resetBossEmailAction.AddParameter("emails", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false))));
            model.AddElement(resetBossEmailAction);
            defaultContainer.AddActionImport(resetBossEmailAction);

            //UnBound Action : ComplexType parameter, Return ComplexType
            var resetBossAddressAction = new EdmAction(ns, "ResetBossAddress", new EdmComplexTypeReference(addressType, false), false, null);
            resetBossAddressAction.AddParameter("address", new EdmComplexTypeReference(addressType, false));
            model.AddElement(resetBossAddressAction);
            defaultContainer.AddActionImport(resetBossAddressAction);

            //UnBound Action: ResetDataSource
            var resetDataSourceAction = new EdmAction(ns, "ResetDataSource", null, false, null);
            model.AddElement(resetDataSourceAction);
            defaultContainer.AddActionImport(resetDataSourceAction);

            //Bound Function : Bound to Singleton, Return PrimitiveType
            EdmFunction getCompanyEmployeeCount = new EdmFunction(ns, "GetEmployeesCount", EdmCoreModel.Instance.GetInt32(false), /*isBound*/true, /*entitySetPathExpression*/null, /*isComposable*/false);
            getCompanyEmployeeCount.AddParameter(new EdmOperationParameter(getCompanyEmployeeCount, "p", new EdmEntityTypeReference(companyType, false)));
            model.AddElement(getCompanyEmployeeCount);

            //Bound Function : Bound to Entity, Return CollectionOfEntity
            var getProductDetailsFunction = new EdmFunction(ns, "GetProductDetails",
                new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(productDetailType, false))),
                true, new EdmPathExpression("product/Details"), true);
            getProductDetailsFunction.AddParameter("product", new EdmEntityTypeReference(productType, false));
            getProductDetailsFunction.AddParameter("count", EdmCoreModel.Instance.GetInt32(true));
            model.AddElement(getProductDetailsFunction);

            //Bound Function : Bound to Entity, Return Entity
            var getRelatedProductFunction = new EdmFunction(ns, "GetRelatedProduct",
                new EdmEntityTypeReference(productType, false),
                true, new EdmPathExpression("productDetail/RelatedProduct"), true);
            getRelatedProductFunction.AddParameter("productDetail", new EdmEntityTypeReference(productDetailType, false));
            model.AddElement(getRelatedProductFunction);

            //Bound Function : Bound to Entity, Return Collection of Abstract Entity
            var getOrderAndOrderDetails = new EdmFunction(ns, "getOrderAndOrderDetails",
                new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(abstractType, false))),
                true, new EdmPathExpression("customer/Orders"), true);
            getOrderAndOrderDetails.AddParameter("customer", new EdmEntityTypeReference(customerType, false));
            model.AddElement(getOrderAndOrderDetails);

            //Bound Function : Bound to CollectionOfEntity, Return Entity
            var getSeniorEmployees = new EdmFunction(ns, "GetSeniorEmployees",
                new EdmEntityTypeReference(employeeType, true),
                true, new EdmPathExpression("employees"), true);
            getSeniorEmployees.AddParameter("employees", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(employeeType, false))));
            model.AddElement(getSeniorEmployees);

            //Bound Function : Bound to Order, Return Edm.Date
            var getOrderShipDate = new EdmFunction(ns, "GetShipDate", EdmCoreModel.Instance.GetDate(false), true, null, false);
            getOrderShipDate.AddParameter("order", new EdmEntityTypeReference(orderType, false));
            model.AddElement(getOrderShipDate);

            //Bound Function : Bound to Order, Return Edm.TimeOfDay
            var getOrderShipTime = new EdmFunction(ns, "GetShipTime", EdmCoreModel.Instance.GetTimeOfDay(false), true, null, false);
            getOrderShipTime.AddParameter("order", new EdmEntityTypeReference(orderType, false));
            model.AddElement(getOrderShipTime);

            //Bound Function : Bound to Order, Parameter: Edm.TimeOfDay, Return Edm.Boolean
            var checkOrderShipTime = new EdmFunction(ns, "CheckShipTime", EdmCoreModel.Instance.GetBoolean(false), true, null, false);
            checkOrderShipTime.AddParameter("order", new EdmEntityTypeReference(orderType, false));
            checkOrderShipTime.AddParameter("time", EdmCoreModel.Instance.GetTimeOfDay(false));
            model.AddElement(checkOrderShipTime);

            //Bound Function : Bound to Order, Parameter: Edm.Date, Return Edm.Boolean
            var checkOrderShipDate = new EdmFunction(ns, "CheckShipDate", EdmCoreModel.Instance.GetBoolean(false), true, null, false);
            checkOrderShipDate.AddParameter("order", new EdmEntityTypeReference(orderType, false));
            checkOrderShipDate.AddParameter("date", EdmCoreModel.Instance.GetDate(false));
            model.AddElement(checkOrderShipDate);

            //UnBound Function : Return EnumType
            var defaultColorFunction = new EdmFunction(ns, "GetDefaultColor", new EdmEnumTypeReference(colorType, true), false, null, true);
            model.AddElement(defaultColorFunction);
            defaultContainer.AddFunctionImport("GetDefaultColor", defaultColorFunction, null, true);

            //UnBound Function : Complex Parameter, Return Entity
            var getPersonFunction = new EdmFunction(ns, "GetPerson",
                new EdmEntityTypeReference(personType, false),
                false, null, true);
            getPersonFunction.AddParameter("address", new EdmComplexTypeReference(addressType, false));
            model.AddElement(getPersonFunction);
            defaultContainer.AddFunctionImport("GetPerson", getPersonFunction, new EdmEntitySetReferenceExpression(personSet), true);

            //UnBound Function : Primtive Parameter, Return Entity
            var getPersonFunction2 = new EdmFunction(ns, "GetPerson2",
                new EdmEntityTypeReference(personType, false),
                false, null, true);
            getPersonFunction2.AddParameter("city", EdmCoreModel.Instance.GetString(false));
            model.AddElement(getPersonFunction2);
            defaultContainer.AddFunctionImport("GetPerson2", getPersonFunction2, new EdmEntitySetReferenceExpression(personSet), true);

            //UnBound Function : Return CollectionOfEntity
            var getAllProductsFunction = new EdmFunction(ns, "GetAllProducts",
                new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(productType, false))),
                false, null, true);
            model.AddElement(getAllProductsFunction);
            defaultContainer.AddFunctionImport("GetAllProducts", getAllProductsFunction, new EdmEntitySetReferenceExpression(productSet), true);

            //UnBound Function : Multi ParameterS Return Collection Of ComplexType
            var getBossEmailsFunction = new EdmFunction(ns, "GetBossEmails",
                new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false))),
                false, null, false);
            getBossEmailsFunction.AddParameter("start", EdmCoreModel.Instance.GetInt32(false));
            getBossEmailsFunction.AddParameter("count", EdmCoreModel.Instance.GetInt32(false));
            model.AddElement(getBossEmailsFunction);
            defaultContainer.AddFunctionImport(getBossEmailsFunction.Name, getBossEmailsFunction, null, true);

            var getProductsByAccessLevelFunction = new EdmFunction(ns, "GetProductsByAccessLevel",
                new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false))),
                false, null, false);
            getProductsByAccessLevelFunction.AddParameter("accessLevel", new EdmEnumTypeReference(accessLevelType, false));
            model.AddElement(getProductsByAccessLevelFunction);
            defaultContainer.AddFunctionImport(getProductsByAccessLevelFunction.Name, getProductsByAccessLevelFunction, null, true);

            #endregion

            #endregion

            #region For containment

            var accountInfoType = new EdmComplexType(ns, "AccountInfo", null, false, true);
            accountInfoType.AddProperty(new EdmStructuralProperty(accountInfoType, "FirstName", EdmCoreModel.Instance.GetString(false)));
            accountInfoType.AddProperty(new EdmStructuralProperty(accountInfoType, "LastName", EdmCoreModel.Instance.GetString(false)));

            var accountType = new EdmEntityType(ns, "Account");
            var accountIdProperty = new EdmStructuralProperty(accountType, "AccountID", EdmCoreModel.Instance.GetInt32(false));
            accountType.AddProperty(accountIdProperty);
            accountType.AddKeys(accountIdProperty);
            accountType.AddProperty(new EdmStructuralProperty(accountType, "CountryRegion", EdmCoreModel.Instance.GetString(false)));
            accountType.AddProperty(new EdmStructuralProperty(accountType, "AccountInfo", new EdmComplexTypeReference(accountInfoType, true)));

            var giftCardType = new EdmEntityType(ns, "GiftCard");
            var giftCardIdProperty = new EdmStructuralProperty(giftCardType, "GiftCardID", EdmCoreModel.Instance.GetInt32(false));
            giftCardType.AddProperty(giftCardIdProperty);
            giftCardType.AddKeys(giftCardIdProperty);
            giftCardType.AddProperty(new EdmStructuralProperty(giftCardType, "GiftCardNO", EdmCoreModel.Instance.GetString(false)));
            giftCardType.AddProperty(new EdmStructuralProperty(giftCardType, "Amount", EdmCoreModel.Instance.GetDouble(false)));
            giftCardType.AddProperty(new EdmStructuralProperty(giftCardType, "ExperationDate", EdmCoreModel.Instance.GetDateTimeOffset(false)));
            giftCardType.AddProperty(new EdmStructuralProperty(giftCardType, "OwnerName", EdmCoreModel.Instance.GetString(true)));


            var paymentInstrumentType = new EdmEntityType(ns, "PaymentInstrument");
            var paymentInstrumentIdProperty = new EdmStructuralProperty(paymentInstrumentType, "PaymentInstrumentID", EdmCoreModel.Instance.GetInt32(false));
            paymentInstrumentType.AddProperty(paymentInstrumentIdProperty);
            paymentInstrumentType.AddKeys(paymentInstrumentIdProperty);
            paymentInstrumentType.AddProperty(new EdmStructuralProperty(paymentInstrumentType, "FriendlyName", EdmCoreModel.Instance.GetString(false)));
            paymentInstrumentType.AddProperty(new EdmStructuralProperty(paymentInstrumentType, "CreatedDate", EdmCoreModel.Instance.GetDateTimeOffset(false)));

            var creditCardType = new EdmEntityType(ns, "CreditCardPI", paymentInstrumentType);
            creditCardType.AddProperty(new EdmStructuralProperty(creditCardType, "CardNumber", EdmCoreModel.Instance.GetString(false)));
            creditCardType.AddProperty(new EdmStructuralProperty(creditCardType, "CVV", EdmCoreModel.Instance.GetString(false)));
            creditCardType.AddProperty(new EdmStructuralProperty(creditCardType, "HolderName", EdmCoreModel.Instance.GetString(false)));
            creditCardType.AddProperty(new EdmStructuralProperty(creditCardType, "Balance", EdmCoreModel.Instance.GetDouble(false)));
            creditCardType.AddProperty(new EdmStructuralProperty(creditCardType, "ExperationDate", EdmCoreModel.Instance.GetDateTimeOffset(false)));

            var storedPIType = new EdmEntityType(ns, "StoredPI");
            var storedPIIdProperty = new EdmStructuralProperty(storedPIType, "StoredPIID", EdmCoreModel.Instance.GetInt32(false));
            storedPIType.AddProperty(storedPIIdProperty);
            storedPIType.AddKeys(storedPIIdProperty);
            storedPIType.AddProperty(new EdmStructuralProperty(storedPIType, "PIName", EdmCoreModel.Instance.GetString(false)));
            storedPIType.AddProperty(new EdmStructuralProperty(storedPIType, "PIType", EdmCoreModel.Instance.GetString(false)));
            storedPIType.AddProperty(new EdmStructuralProperty(storedPIType, "CreatedDate", EdmCoreModel.Instance.GetDateTimeOffset(false)));

            var statementType = new EdmEntityType(ns, "Statement");
            var statementIdProperty = new EdmStructuralProperty(statementType, "StatementID", EdmCoreModel.Instance.GetInt32(false));
            statementType.AddProperty(statementIdProperty);
            statementType.AddKeys(statementIdProperty);
            statementType.AddProperty(new EdmStructuralProperty(statementType, "TransactionType", EdmCoreModel.Instance.GetString(false)));
            statementType.AddProperty(new EdmStructuralProperty(statementType, "TransactionDescription", EdmCoreModel.Instance.GetString(false)));
            statementType.AddProperty(new EdmStructuralProperty(statementType, "Amount", EdmCoreModel.Instance.GetDouble(false)));

            var creditRecordType = new EdmEntityType(ns, "CreditRecord");
            var creditRecordIdProperty = new EdmStructuralProperty(creditRecordType, "CreditRecordID", EdmCoreModel.Instance.GetInt32(false));
            creditRecordType.AddProperty(creditRecordIdProperty);
            creditRecordType.AddKeys(creditRecordIdProperty);
            creditRecordType.AddProperty(new EdmStructuralProperty(creditRecordType, "IsGood", EdmCoreModel.Instance.GetBoolean(false)));
            creditRecordType.AddProperty(new EdmStructuralProperty(creditRecordType, "Reason", EdmCoreModel.Instance.GetString(false)));
            creditRecordType.AddProperty(new EdmStructuralProperty(creditRecordType, "CreatedDate", EdmCoreModel.Instance.GetDateTimeOffset(false)));

            var subscriptionType = new EdmEntityType(ns, "Subscription");
            var subscriptionIdProperty = new EdmStructuralProperty(subscriptionType, "SubscriptionID", EdmCoreModel.Instance.GetInt32(false));
            subscriptionType.AddProperty(subscriptionIdProperty);
            subscriptionType.AddKeys(subscriptionIdProperty);
            subscriptionType.AddProperty(new EdmStructuralProperty(subscriptionType, "TemplateGuid", EdmCoreModel.Instance.GetString(false)));
            subscriptionType.AddProperty(new EdmStructuralProperty(subscriptionType, "Title", EdmCoreModel.Instance.GetString(false)));
            subscriptionType.AddProperty(new EdmStructuralProperty(subscriptionType, "Category", EdmCoreModel.Instance.GetString(false)));
            subscriptionType.AddProperty(new EdmStructuralProperty(subscriptionType, "CreatedDate", EdmCoreModel.Instance.GetDateTimeOffset(false)));

            #region Functions/Actions
            var giftCardAmountFunction = new EdmFunction(ns, "GetActualAmount", EdmCoreModel.Instance.GetDouble(false), true, null, false);
            giftCardAmountFunction.AddParameter("giftcard", new EdmEntityTypeReference(giftCardType, false));
            giftCardAmountFunction.AddParameter("bonusRate", EdmCoreModel.Instance.GetDouble(true));
            model.AddElement(giftCardAmountFunction);

            var accountDefaultPIFunction = new EdmFunction(ns, "GetDefaultPI", new EdmEntityTypeReference(paymentInstrumentType, true), true, new EdmPathExpression("account/MyPaymentInstruments"), false);
            accountDefaultPIFunction.AddParameter("account", new EdmEntityTypeReference(accountType, false));
            model.AddElement(accountDefaultPIFunction);

            var accountRefreshDefaultPIAction = new EdmAction(ns, "RefreshDefaultPI", new EdmEntityTypeReference(paymentInstrumentType, true), true, new EdmPathExpression("account/MyPaymentInstruments"));
            accountRefreshDefaultPIAction.AddParameter("account", new EdmEntityTypeReference(accountType, false));
            accountRefreshDefaultPIAction.AddParameter("newDate", EdmCoreModel.Instance.GetDateTimeOffset(true));
            model.AddElement(accountRefreshDefaultPIAction);

            //Bound Function : Bound to Entity, Return ComplexType
            var getHomeAddressFunction = new EdmFunction(ns, "GetHomeAddress",
                new EdmComplexTypeReference(homeAddressType, false),
                true, null, true);
            getHomeAddressFunction.AddParameter("person", new EdmEntityTypeReference(personType, false));
            model.AddElement(getHomeAddressFunction);

            //Bound Function : Bound to Entity, Return ComplexType
            var getAccountInfoFunction = new EdmFunction(ns, "GetAccountInfo",
                new EdmComplexTypeReference(accountInfoType, false),
                true, null, true);
            getAccountInfoFunction.AddParameter("account", new EdmEntityTypeReference(accountType, false));
            model.AddElement(getAccountInfoFunction);

            #endregion

            var accountGiftCardNavigation = accountType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name = "MyGiftCard",
                Target = giftCardType,
                TargetMultiplicity = EdmMultiplicity.ZeroOrOne,
                ContainsTarget = true
            });

            var accountPIsNavigation = accountType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name = "MyPaymentInstruments",
                Target = paymentInstrumentType,
                TargetMultiplicity = EdmMultiplicity.Many,
                ContainsTarget = true
            });

            var accountActiveSubsNavigation = accountType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name = "ActiveSubscriptions",
                Target = subscriptionType,
                TargetMultiplicity = EdmMultiplicity.Many,
                ContainsTarget = true
            });

            var accountAvailableSubsTemplatesNavigation = accountType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name = "AvailableSubscriptionTemplatess",
                Target = subscriptionType,
                TargetMultiplicity = EdmMultiplicity.Many,
                ContainsTarget = false
            });

            var piStoredNavigation = paymentInstrumentType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name = "TheStoredPI",
                Target = storedPIType,
                TargetMultiplicity = EdmMultiplicity.One,
                ContainsTarget = false
            });

            var piStatementsNavigation = paymentInstrumentType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name = "BillingStatements",
                Target = statementType,
                TargetMultiplicity = EdmMultiplicity.Many,
                ContainsTarget = true
            });

            var piBackupStoredPINavigation = paymentInstrumentType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name = "BackupStoredPI",
                Target = storedPIType,
                TargetMultiplicity = EdmMultiplicity.One,
                ContainsTarget = false
            });

            var creditCardCreditRecordNavigation = creditCardType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name = "CreditRecords",
                Target = creditRecordType,
                TargetMultiplicity = EdmMultiplicity.Many,
                ContainsTarget = true
            });

            model.AddElement(accountInfoType);
            model.AddElement(accountType);
            model.AddElement(giftCardType);
            model.AddElement(paymentInstrumentType);
            model.AddElement(creditCardType);
            model.AddElement(storedPIType);
            model.AddElement(statementType);
            model.AddElement(creditRecordType);
            model.AddElement(subscriptionType);

            var accountSet = new EdmEntitySet(defaultContainer, "Accounts", accountType);
            defaultContainer.AddElement(accountSet);
            var storedPISet = new EdmEntitySet(defaultContainer, "StoredPIs", storedPIType);
            defaultContainer.AddElement(storedPISet);
            var subscriptionTemplatesSet = new EdmEntitySet(defaultContainer, "SubscriptionTemplates", subscriptionType);
            defaultContainer.AddElement(subscriptionTemplatesSet);
            var defaultStoredPI = new EdmSingleton(defaultContainer, "DefaultStoredPI", storedPIType);
            defaultContainer.AddElement(defaultStoredPI);

            ((EdmEntitySet)accountSet).AddNavigationTarget(piStoredNavigation, storedPISet);
            ((EdmEntitySet)accountSet).AddNavigationTarget(accountAvailableSubsTemplatesNavigation, subscriptionTemplatesSet);
            ((EdmEntitySet)accountSet).AddNavigationTarget(piBackupStoredPINavigation, defaultStoredPI);

            #endregion

            IEnumerable<EdmError> errors = null;
            model.Validate(out errors);
            //TODO: Fix the errors

            return model;
        }
        public static EdmModel GetModelWithServiceOperationWithMissingReturnSet()
        {
            EdmEntityType vegetableType = new EdmEntityType("Test", "Vegetable");
            IEdmStructuralProperty id = vegetableType.AddStructuralProperty("ID", EdmCoreModel.Instance.GetInt32(false));
            vegetableType.AddKeys(id);

            // Note how the entity set expression is null even though it returns an entity
            EdmEntityContainer container = new EdmEntityContainer("Test", "Container");
            var function = new EdmFunction("Test", "Container", new EdmEntityTypeReference(vegetableType, true));
            container.AddFunctionImport("GetVegetableWithMissingSet", function, null);

            EdmModel model = new EdmModel();
            model.AddElement(container);
            model.AddElement(vegetableType);
            return model;
        }
        public static IEdmModel GetModelWithFunctionOverloadsWithSameParameterNames()
        {
            EdmEntityType vegetableType = new EdmEntityType("Test", "Vegetable");
            IEdmStructuralProperty id = vegetableType.AddStructuralProperty("ID", EdmCoreModel.Instance.GetInt32(false));
            vegetableType.AddKeys(id);

            EdmEntityContainer container = new EdmEntityContainer("Test", "Container");
            var set = container.AddEntitySet("Vegetables", vegetableType); 
            
            var function1 = new EdmFunction("Test", "Foo", new EdmEntityTypeReference(vegetableType, true), true/*isBound*/, null, true /*isComposable*/);
            function1.AddParameter("p1", new EdmEntityTypeReference(vegetableType, false));
            function1.AddParameter("p2", EdmCoreModel.Instance.GetInt32(false));
            
            container.AddFunctionImport("Foo", function1, new EdmEntitySetReferenceExpression(set));

            var function2 = new EdmFunction("Test", "Foo", new EdmEntityTypeReference(vegetableType, true), true /*isBound*/, null, true /*isComposable*/);
            function2.AddParameter("p1", new EdmEntityTypeReference(vegetableType, false));
            function2.AddParameter("p2", EdmCoreModel.Instance.GetString(false));
            container.AddFunctionImport("Foo", function2, new EdmEntitySetReferenceExpression(set));

            EdmModel model = new EdmModel();
            model.AddElement(container);
            model.AddElement(vegetableType);
            model.AddElement(function1);
            model.AddElement(function2);
            return model;
        }
        public static IEdmModel GetModelFunctionsOnNonEntityTypes()
        {
            EdmComplexType colorInfoType = new EdmComplexType("Test", "ColorInfo");
            colorInfoType.AddProperty(new EdmStructuralProperty(colorInfoType, "Red", EdmCoreModel.Instance.GetInt32(false)));
            colorInfoType.AddProperty(new EdmStructuralProperty(colorInfoType, "Green", EdmCoreModel.Instance.GetInt32(false)));
            colorInfoType.AddProperty(new EdmStructuralProperty(colorInfoType, "Blue", EdmCoreModel.Instance.GetInt32(false)));

            EdmEntityType vegetableType = new EdmEntityType("Test", "Vegetable");
            IEdmStructuralProperty id = vegetableType.AddStructuralProperty("ID", EdmCoreModel.Instance.GetInt32(false));
            vegetableType.AddKeys(id);
            vegetableType.AddStructuralProperty("Color", new EdmComplexTypeReference(colorInfoType, false));

            EdmEntityContainer container = new EdmEntityContainer("Test", "Container");
            var set = container.AddEntitySet("Vegetables", vegetableType);

            var function1 = new EdmFunction("Test", "IsPrime", EdmCoreModel.Instance.GetBoolean(false), true, null, true);
            function1.AddParameter("integer", EdmCoreModel.Instance.GetInt32(false));
            container.AddFunctionImport("IsPrime", function1);

            var action = new EdmAction("Test", "Subtract", EdmCoreModel.Instance.GetInt32(false), true /*isBound*/, null /*entitySetPath*/);
            action.AddParameter("integer", EdmCoreModel.Instance.GetInt32(false));
            container.AddActionImport(action);

            var function2 = new EdmFunction("Test", "IsDark", EdmCoreModel.Instance.GetBoolean(false), true, null, true);
            function2.AddParameter("color", new EdmComplexTypeReference(colorInfoType, false));
            container.AddFunctionImport("IsDark", function2);
            
            var function3 = new EdmFunction("Test", "IsDarkerThan", EdmCoreModel.Instance.GetBoolean(false), true, null, true);
            function3.AddParameter("color", new EdmComplexTypeReference(colorInfoType, false));
            function3.AddParameter("other", new EdmComplexTypeReference(colorInfoType, true));
            container.AddFunctionImport("IsDarkerThan", function3);

            var function4 = new EdmFunction("Test", "GetMostPopularVegetableWithThisColor", new EdmEntityTypeReference(vegetableType, true), true, new EdmPathExpression("color"), true);
            function4.AddParameter("color", new EdmComplexTypeReference(colorInfoType, false));
 
            EdmModel model = new EdmModel();
            model.AddElement(container);
            model.AddElement(vegetableType);
            model.AddElement(action);
            model.AddElement(function1);
            model.AddElement(function2);
            model.AddElement(function3);
            model.AddElement(function4);
            return model;
        }
        private IEdmModel GetEdmModel()
        {
            EdmModel model = new EdmModel();
            EdmEntityContainer container = new EdmEntityContainer("NS", "Name");
            model.AddElement(container);
            var entityType = new EdmEntityType("NS", "EntityTypeName");
            model.AddElement(entityType);
            container.AddEntitySet("EntitySet", entityType);

            IEdmTypeReference returnType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
            IEdmTypeReference parameterType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
            IEdmTypeReference stringType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.String, isNullable: false);

            // unbound function without parameter
            container.AddFunctionImport(new EdmFunction("NS", "FunctionWithoutParams", returnType));

            // unbound function with one parameter
            var functionWithOneParam = new EdmFunction("NS", "FunctionWithOneParam", returnType);
            functionWithOneParam.AddParameter("Parameter", parameterType);
            container.AddFunctionImport(functionWithOneParam);

            // unbound function with multiple parameters
            var functionWithMultipleParams = new EdmFunction("NS", "FunctionWithMultipleParams", returnType);
            functionWithMultipleParams.AddParameter("Parameter1", parameterType);
            functionWithMultipleParams.AddParameter("Parameter2", parameterType);
            functionWithMultipleParams.AddParameter("Parameter3", parameterType);
            container.AddFunctionImport(functionWithMultipleParams);

            // unbound overload function
            container.AddFunctionImport(new EdmFunction("NS", "FunctionWithOverloads", returnType));
            var functionWithOverloads2 = new EdmFunction("NS", "FunctionWithOverloads", returnType);
            functionWithOverloads2.AddParameter("Parameter", parameterType);
            container.AddFunctionImport(functionWithOverloads2);

            var functionWithOverloads3 = new EdmFunction("NS", "FunctionWithOverloads", returnType);
            functionWithOverloads3.AddParameter("Parameter1", parameterType);
            functionWithOverloads3.AddParameter("Parameter2", parameterType);
            functionWithOverloads3.AddParameter("Parameter3", parameterType);
            container.AddFunctionImport(functionWithOverloads3);

            // bound function with only binding parameter
            IEdmTypeReference bindingParamterType = new EdmEntityTypeReference(entityType, isNullable: false);
            var boundFunction = new EdmFunction("NS", "BoundFunctionWithoutParams", returnType, true, null, true);
            boundFunction.AddParameter("bindingParameter", bindingParamterType);
            model.AddElement(boundFunction);

            // bound function with binding and one non-binding parameter
            boundFunction = new EdmFunction("NS", "BoundFunctionWithOneParam", returnType, true, null, true);
            boundFunction.AddParameter("bindingParameter", bindingParamterType);
            boundFunction.AddParameter("Parameter", parameterType);
            model.AddElement(boundFunction);

            // bound function with binding and multiple non-binding parameters
            boundFunction = new EdmFunction("NS", "BoundFunctionWithMultipleParams", returnType, true, null, true);
            boundFunction.AddParameter("bindingParameter", bindingParamterType);
            boundFunction.AddParameter("Parameter1", parameterType);
            boundFunction.AddParameter("Parameter2", parameterType);
            boundFunction.AddParameter("Parameter3", parameterType);
            model.AddElement(boundFunction);

            // bound overload function with only binding parameter
            boundFunction = new EdmFunction("NS", "BoundFunctionOverload", returnType, true, null, true);
            boundFunction.AddParameter("bindingParameter", bindingParamterType);
            model.AddElement(boundFunction);

            // bound overload function with binding and one non-binding parameter
            boundFunction = new EdmFunction("NS", "BoundFunctionOverload", returnType, true, null, true);
            boundFunction.AddParameter("bindingParameter", bindingParamterType);
            boundFunction.AddParameter("Parameter", parameterType);
            model.AddElement(boundFunction);

            // bound overload function with binding and multiple non-binding parameters
            boundFunction = new EdmFunction("NS", "BoundFunctionOverload", returnType, true, null, true);
            boundFunction.AddParameter("bindingParameter", bindingParamterType);
            boundFunction.AddParameter("Parameter1", parameterType);
            boundFunction.AddParameter("Parameter2", parameterType);
            boundFunction.AddParameter("Parameter3", parameterType);
            model.AddElement(boundFunction);

            // the following two bound functions have the same function name, same binding type and the same parameter name,
            // but the non-binding parameter type is different.
            boundFunction = new EdmFunction("NS", "BoundOverloadFailed", returnType, true, null, true);
            boundFunction.AddParameter("bindingParameter", bindingParamterType);
            boundFunction.AddParameter("FunctionParameter", parameterType);
            model.AddElement(boundFunction);

            boundFunction = new EdmFunction("NS", "BoundOverloadFailed", returnType, true, null, true);
            boundFunction.AddParameter("bindingParameter", bindingParamterType);
            boundFunction.AddParameter("FunctionParameter", stringType);
            model.AddElement(boundFunction);

            // the following two unbound functions have the same function name and the same parameter name,
            // but the parameter type is different.
            var function = new EdmFunction("NS", "UnboundOverloadFailed", returnType);
            function.AddParameter("FunctionParameter", parameterType);
            container.AddFunctionImport(function);

            function = new EdmFunction("NS", "UnboundOverloadFailed", returnType);
            function.AddParameter("FunctionParameter", stringType);
            container.AddFunctionImport(function);

            return model;
        }
        public CustomersModelWithInheritance()
        {
            EdmModel model = new EdmModel();

            // Enum type simpleEnum
            EdmEnumType simpleEnum = new EdmEnumType("NS", "SimpleEnum");
            simpleEnum.AddMember(new EdmEnumMember(simpleEnum, "First", new EdmIntegerConstant(0)));
            simpleEnum.AddMember(new EdmEnumMember(simpleEnum, "Second", new EdmIntegerConstant(1)));
            simpleEnum.AddMember(new EdmEnumMember(simpleEnum, "Third", new EdmIntegerConstant(2)));
            model.AddElement(simpleEnum);

            // complex type address
            EdmComplexType address = new EdmComplexType("NS", "Address");
            address.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String);
            address.AddStructuralProperty("City", EdmPrimitiveTypeKind.String);
            address.AddStructuralProperty("State", EdmPrimitiveTypeKind.String);
            address.AddStructuralProperty("ZipCode", EdmPrimitiveTypeKind.String);
            address.AddStructuralProperty("Country", EdmPrimitiveTypeKind.String);
            model.AddElement(address);

            // entity type customer
            EdmEntityType customer = new EdmEntityType("NS", "Customer");
            customer.AddKeys(customer.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
            IEdmProperty customerName = customer.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            customer.AddStructuralProperty("SimpleEnum", simpleEnum.ToEdmTypeReference(isNullable: false));
            customer.AddStructuralProperty("Address", new EdmComplexTypeReference(address, isNullable: true));
            IEdmTypeReference primitiveTypeReference = EdmCoreModel.Instance.GetPrimitive(
                EdmPrimitiveTypeKind.String,
                isNullable: true);
            customer.AddStructuralProperty(
                "City",
                primitiveTypeReference,
                defaultValue: null,
                concurrencyMode: EdmConcurrencyMode.Fixed);
            model.AddElement(customer);

            // derived entity type special customer
            EdmEntityType specialCustomer = new EdmEntityType("NS", "SpecialCustomer", customer);
            specialCustomer.AddStructuralProperty("SpecialCustomerProperty", EdmPrimitiveTypeKind.Guid);
            model.AddElement(specialCustomer);

            // entity type order
            EdmEntityType order = new EdmEntityType("NS", "Order");
            order.AddKeys(order.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
            order.AddStructuralProperty("Amount", EdmPrimitiveTypeKind.Int32);
            model.AddElement(order);

            // derived entity type special order
            EdmEntityType specialOrder = new EdmEntityType("NS", "SpecialOrder", order);
            specialOrder.AddStructuralProperty("SpecialOrderProperty", EdmPrimitiveTypeKind.Guid);
            model.AddElement(specialOrder);

            // test entity
            EdmEntityType testEntity = new EdmEntityType("System.Web.OData.Query.Expressions", "TestEntity");
            testEntity.AddStructuralProperty("SampleProperty", EdmPrimitiveTypeKind.Binary);
            model.AddElement(testEntity);

            // entity sets
            EdmEntityContainer container = new EdmEntityContainer("NS", "ModelWithInheritance");
            model.AddElement(container);
            EdmEntitySet customers = container.AddEntitySet("Customers", customer);
            EdmEntitySet orders = container.AddEntitySet("Orders", order);

            // actions
            EdmAction upgrade = new EdmAction("NS", "upgrade", returnType: null, isBound: true, entitySetPathExpression: null);
            upgrade.AddParameter("entity", new EdmEntityTypeReference(customer, false));
            model.AddElement(upgrade);
            EdmActionImport upgradeCustomer = container.AddActionImport(
                "upgrade",
                upgrade,
                new EdmEntitySetReferenceExpression(customers));

            EdmAction specialUpgrade =
                new EdmAction("NS", "specialUpgrade", returnType: null, isBound: true, entitySetPathExpression: null);
            specialUpgrade.AddParameter("entity", new EdmEntityTypeReference(specialCustomer, false));
            model.AddElement(specialUpgrade);
            EdmActionImport upgradeSpecialCustomer = container.AddActionImport(
                "specialUpgrade",
                specialUpgrade,
                new EdmEntitySetReferenceExpression(customers));

            // functions
            IEdmTypeReference returnType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
            EdmFunction IsUpgraded = new EdmFunction(
                "NS",
                "IsUpgraded",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            IsUpgraded.AddParameter("entity", new EdmEntityTypeReference(customer, false));
            model.AddElement(IsUpgraded);
            EdmFunctionImport isCustomerUpgraded = container.AddFunctionImport(
                "IsUpgraded",
                IsUpgraded,
                new EdmEntitySetReferenceExpression(customers));

            EdmFunction IsSpecialUpgraded = new EdmFunction(
                "NS",
                "IsSpecialUpgraded",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            IsSpecialUpgraded.AddParameter("entity", new EdmEntityTypeReference(specialCustomer, false));
            model.AddElement(IsSpecialUpgraded);
            var isSpecialCustomerUpgraded = container.AddFunctionImport(
                "IsSpecialUpgraded",
                IsSpecialUpgraded,
                new EdmEntitySetReferenceExpression(customers));

            EdmFunction IsAnyUpgraded = new EdmFunction(
                "NS",
                "IsAnyUpgraded",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            EdmCollectionType edmCollectionType = new EdmCollectionType(new EdmEntityTypeReference(customer, false));
            IsAnyUpgraded.AddParameter("entityset", new EdmCollectionTypeReference(edmCollectionType));
            model.AddElement(IsAnyUpgraded);
            container.AddFunctionImport(
                "IsAnyUpgraded",
                IsAnyUpgraded,
                new EdmEntitySetReferenceExpression(customers));

            EdmFunction isCustomerUpgradedWithParam = new EdmFunction(
                "NS",
                "IsUpgradedWithParam",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            isCustomerUpgradedWithParam.AddParameter("entity", new EdmEntityTypeReference(customer, false));
            isCustomerUpgradedWithParam.AddParameter("city", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.String, isNullable: false));
            model.AddElement(isCustomerUpgradedWithParam);
            container.AddFunctionImport(
                "IsUpgradedWithParam",
                isCustomerUpgradedWithParam,
                new EdmEntitySetReferenceExpression(customers));

            EdmFunction isCustomerLocal = new EdmFunction(
                "NS",
                "IsLocal",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            isCustomerLocal.AddParameter("entity", new EdmEntityTypeReference(customer, false));
            model.AddElement(isCustomerLocal);
            container.AddFunctionImport(
                "IsLocal",
                isCustomerLocal,
                new EdmEntitySetReferenceExpression(customers));

            // navigation properties
            customers.AddNavigationTarget(
                customer.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
                {
                    Name = "Orders",
                    TargetMultiplicity = EdmMultiplicity.Many,
                    Target = order
                }),
                orders);
            orders.AddNavigationTarget(
                 order.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
                 {
                     Name = "Customer",
                     TargetMultiplicity = EdmMultiplicity.ZeroOrOne,
                     Target = customer
                 }),
                customers);

            // navigation properties on derived types.
            customers.AddNavigationTarget(
                specialCustomer.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
                {
                    Name = "SpecialOrders",
                    TargetMultiplicity = EdmMultiplicity.Many,
                    Target = order
                }),
                orders);
            orders.AddNavigationTarget(
                 specialOrder.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
                 {
                     Name = "SpecialCustomer",
                     TargetMultiplicity = EdmMultiplicity.ZeroOrOne,
                     Target = customer
                 }),
                customers);
            model.SetAnnotationValue<BindableProcedureFinder>(model, new BindableProcedureFinder(model));

            // set properties
            Model = model;
            Container = container;
            Customer = customer;
            Order = order;
            Address = address;
            SpecialCustomer = specialCustomer;
            SpecialOrder = specialOrder;
            Orders = orders;
            Customers = customers;
            UpgradeCustomer = upgradeCustomer;
            UpgradeSpecialCustomer = upgradeSpecialCustomer;
            CustomerName = customerName;
            IsCustomerUpgraded = isCustomerUpgraded;
            IsSpecialCustomerUpgraded = isSpecialCustomerUpgraded;
        }
 public void GetTargetEntitySetForFunctionWithNoStaticSetOrSourceSetShouldBeNull()
 {
     var model = new EdmModel();
     var container = new EdmEntityContainer("Fake", "Container");
     model.AddElement(container);
     var function = new EdmFunction("Fake", "FakeFunction", new EdmEntityTypeReference(new EdmEntityType("Fake", "EntityType"), false));
     var expression = new EdmPathExpression("p1/Navigation1");
     var operationImport = container.AddFunctionImport("FakeAction", function, expression);
     operationImport.GetTargetEntitySet(null, model).Should().BeNull();
 }
        public void CollectionPayloadTest()
        {
            IEdmPrimitiveTypeReference int32NullableTypeRef = EdmCoreModel.Instance.GetInt32(isNullable: true);
            IEdmStringTypeReference stringTypeRef = EdmCoreModel.Instance.GetString(isNullable: true);
            var model = new EdmModel();
            var addressType = new EdmComplexType("TestNS", "AddressType");
            addressType.AddStructuralProperty("Street", stringTypeRef);
            addressType.AddStructuralProperty("City", stringTypeRef);
            addressType.AddStructuralProperty("Zip", EdmPrimitiveTypeKind.Int32);
            model.AddElement(addressType);

            var container = new EdmEntityContainer("TestNS", "DefaultContainer");

            var intServiceOp = new EdmFunction("TestNS", "GetIntCollection", EdmCoreModel.GetCollection(int32NullableTypeRef));
            intServiceOp.AddParameter("a", int32NullableTypeRef);
            intServiceOp.AddParameter("b", stringTypeRef);
            var intServiceOpFunctionImport = container.AddFunctionImport("GetIntCollection", intServiceOp);

            EdmFunction stringServiceOp = new EdmFunction("TestNS", "GetStringCollection", EdmCoreModel.GetCollection(stringTypeRef));
            stringServiceOp.AddParameter("a", int32NullableTypeRef);
            stringServiceOp.AddParameter("b", stringTypeRef);
            var stringServiceOpFunctionImport = container.AddFunctionImport("GetStringCollection", stringServiceOp);

            EdmFunction complexServiceOp = new EdmFunction("TestNS", "GetComplexCollection", EdmCoreModel.GetCollection(new EdmComplexTypeReference(addressType, true)));
            complexServiceOp.AddParameter("a", int32NullableTypeRef);
            complexServiceOp.AddParameter("b", stringTypeRef);
            var complexServiceOpFunctionImport = container.AddFunctionImport("GetComplexCollection", complexServiceOp);

            EdmFunction geometryServiceOp = new EdmFunction("TestNS", "GetGeometryCollection", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.Geometry, true)));
            geometryServiceOp.AddParameter("a", int32NullableTypeRef);
            geometryServiceOp.AddParameter("b", stringTypeRef);
            var geometryServiceOpFunctionImport = container.AddFunctionImport("GetGeometryCollection", geometryServiceOp);

            EdmFunction geographyServiceOp = new EdmFunction("TestNS", "GetGeographyCollection", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.Geography, true)));
            geographyServiceOp.AddParameter("a", int32NullableTypeRef);
            geographyServiceOp.AddParameter("b", stringTypeRef);
            var geographyServiceOpFunctionImport = container.AddFunctionImport("GetGeographyCollection", geographyServiceOp);

            model.AddElement(container);
            model.AddElement(intServiceOp);
            model.AddElement(stringServiceOp);
            model.AddElement(complexServiceOp);
            model.AddElement(geometryServiceOp);
            model.AddElement(geographyServiceOp);

            IEnumerable<CollectionWriterTestCase> testCases = new[]
            {
                new CollectionWriterTestCase(new CollectionWriterTestDescriptor.ItemDescription[]
                         {
                             nullItem,
                             intItem(1),
                             intItem(2),
                         }, intServiceOpFunctionImport),

                new CollectionWriterTestCase(new CollectionWriterTestDescriptor.ItemDescription[]
                         {
                             nullItem,
                             stringItem("One"),
                             stringItem("Two"),
                         }, stringServiceOpFunctionImport),

                new CollectionWriterTestCase(new CollectionWriterTestDescriptor.ItemDescription[]
                         {
                             nullItem,
                             complexItem("TestNS.AddressType"),
                             complexItem("TestNS.AddressType"),
                         }, complexServiceOpFunctionImport),

                new CollectionWriterTestCase(new CollectionWriterTestDescriptor.ItemDescription[]
                         {
                             nullItem,
                             GetGeometryPointItem("GeometryPoint"),
                             GetGeometryPolygonItem("GeometryPolygon"),
                             GetGeometryCollectionItem("GeometryCollection"),
                             GetGeometryMultiLineStringItem("GeometryMultiLineString"),
                         }, geometryServiceOpFunctionImport),

                new CollectionWriterTestCase(new CollectionWriterTestDescriptor.ItemDescription[]
                         {
                             nullItem,
                             GetGeographyPointItem("GeographyPoint"),
                             GetGeographyPolygonItem("GeographyPolygon"),
                             GetGeographyCollectionItem("GeographyCollection"),
                             GetGeographyMultiLineStringItem("GeographyMultiLineString"),
                         }, geographyServiceOpFunctionImport),
            };

            IEnumerable<CollectionWriterTestCase> cases = testCases;
            int[] collectionSizes = new int[] { 0, 1, 3 };
            testCases = collectionSizes.SelectMany(length =>
                cases.SelectMany(tc =>
                    tc.Items.Combinations(true, length).Select(items =>
                       new CollectionWriterTestCase(items, tc.FunctionImport))));

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                new bool[] { false, true },
                this.WriterTestConfigurationProvider.ExplicitFormatConfigurationsWithIndent.Where(tc => tc.IsRequest == false),
                (testCase, withModel, testConfig) =>
                {
                    if (testConfig.Format == ODataFormat.Json && !withModel)
                    {
                        return;
                    }

                    IEdmTypeReference type = null;

                    if (withModel)
                    {
                        type = testCase.FunctionImport.Operation.ReturnType.AsCollection().ElementType(); 
                    }

                    CollectionWriterTestDescriptor testDescriptor = new CollectionWriterTestDescriptor(this.Settings, testCase.FunctionImport.Name, testCase.Items, withModel ? model : null)
                    {
                        ItemTypeParameter = type
                    };

                    CollectionWriterUtils.WriteAndVerifyCollectionPayload(testDescriptor, testConfig, this.Assert, this.Logger);
                });
        }
Exemple #27
0
        public static IEdmModel EntityContainerWithOperationImportsEdm()
        {
            var model = new EdmModel();
            var customerType = new EdmEntityType("NS1", "Customer");
            customerType.AddKeys(customerType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
            model.AddElement(customerType);

            var container = new EdmEntityContainer("NS1", "MyContainer");
            var customerSet = container.AddEntitySet("Customer", customerType);

            var function = new EdmFunction("NS1", "GetCustomersExcluding", EdmCoreModel.GetCollection(new EdmEntityTypeReference(customerType, false)), false, null, false);
            function.AddParameter("CustomerId", EdmCoreModel.Instance.GetInt32(true));

            model.AddElement(function);
            container.AddFunctionImport("GetCustomersExcluding", function, new EdmEntitySetReferenceExpression(customerSet));

            model.AddElement(container);
            return model;
        }
        public void OverloadServiceOperationSuccessfullyResolved()
        {
            var model = new EdmModel();

            // Add function without parameter.
            var int32TypeReference = EdmCoreModel.Instance.GetInt32(false);
            var functionWithoutParameter = new EdmFunction("Fully.Qualified.Namespace", "Function", int32TypeReference);
            model.AddElement(functionWithoutParameter);

            // Add function with parameter.
            var functionWithParameter = new EdmFunction("Fully.Qualified.Namespace", "Function", int32TypeReference);
            functionWithParameter.AddParameter("Parameter", int32TypeReference);
            model.AddElement(functionWithParameter);

            // Add function with two parameters.
            var functionWithTwoParameter = new EdmFunction("Fully.Qualified.Namespace", "Function", int32TypeReference);
            functionWithTwoParameter.AddParameter("Parameter", int32TypeReference);
            functionWithTwoParameter.AddParameter("Parameter2", int32TypeReference);
            model.AddElement(functionWithTwoParameter);

            // Add function import.
            var container = new EdmEntityContainer("Fully.Qualified.Namespace", "Container");
            model.AddElement(container);
            var functionImportWithoutParameter = container.AddFunctionImport("FunctionImport", functionWithoutParameter);
            var functionImportWithParameter = container.AddFunctionImport("FunctionImport", functionWithParameter);
            var functionImportWithTwoParameter = container.AddFunctionImport("FunctionImport", functionWithTwoParameter);

            IEdmOperationImport functionImport;

            // Resolve overload function import without parameter.
            var parameters = new string[] { };
            FunctionOverloadResolver.ResolveOperationImportFromList("FunctionImport", parameters, model, out functionImport, ODataUriResolver.Default).Should().BeTrue();
            functionImport.Should().BeSameAs(functionImportWithoutParameter);

            // Resolve overload function import with parameter.
            parameters = new string[] { "Parameter" };
            FunctionOverloadResolver.ResolveOperationImportFromList("FunctionImport", parameters, model, out functionImport, ODataUriResolver.Default).Should().BeTrue();
            functionImport.Should().BeSameAs(functionImportWithParameter);

            // Resolve overload function import with parameter.
            parameters = new string[] { "Parameter", "Parameter2" };
            FunctionOverloadResolver.ResolveOperationImportFromList("FunctionImport", parameters, model, out functionImport, ODataUriResolver.Default).Should().BeTrue();
            functionImport.Should().BeSameAs(functionImportWithTwoParameter);
        }
Exemple #29
0
        public static IEdmModel ModelWithEnumEdm(params IEdmEnumType[] enumTypes)
        {
            var model = new EdmModel();
            var complexType = new EdmComplexType("NS1", "Complex");
            model.AddElement(complexType);
            var entityType = new EdmEntityType("NS1", "Person");
            model.AddElement(entityType);
            var container = new EdmEntityContainer("NS1", "MyContainer");
            model.AddElement(container);

            int counter = 0;
            foreach (var enumType in enumTypes)
            {
                var enumTypeReference = new EdmEnumTypeReference(enumType, false);
                model.AddElement(enumType);
                complexType.AddStructuralProperty("EnumProperty" + counter, enumTypeReference);
                entityType.AddKeys(entityType.AddStructuralProperty("EnumProperty" + counter, enumTypeReference));
                var function = new EdmFunction("NS1", "Function" + counter, enumTypeReference);
                model.AddElement(function);
                container.AddFunctionImport(function);
                function.AddParameter("Param" + counter, enumTypeReference);
                counter++;
            }

            return model;
        }
        private static IEdmEntityContainer GetEntityContainer()
        {
            var entityCollection = new EdmCollectionTypeReference(new EdmCollectionType(_entityType), isNullable: false);
            var derivedEntityCollection = new EdmCollectionTypeReference(new EdmCollectionType(_derivedEntityType), isNullable: false);
            EdmEntityContainer container = new EdmEntityContainer("NS", "Name");

            // non-bindable action
            container.AddActionImport(new EdmAction("NS", "NonBindableAction", returnType: null));

            // action bound to entity
            var actionBoundToEntity = new EdmAction(
                "NS",
                "ActionBoundToEntity",
                returnType: null,
                isBound: true,
                entitySetPathExpression: null);
            actionBoundToEntity.AddParameter("Param", _entityType);
            container.AddActionImport(actionBoundToEntity);

            // action bound to derived entity
            var actionBoundToDerivedEntity = new EdmAction(
                "NS",
                "ActionBoundToDerivedEntity",
                returnType: null,
                isBound: true,
                entitySetPathExpression: null);
            actionBoundToDerivedEntity.AddParameter("Param", _derivedEntityType);
            container.AddActionImport(actionBoundToDerivedEntity);

            // action bound to entity collection
            var actionBoundToEntityCollection = new EdmAction(
                "NS",
                "ActionBoundToEntityCollection",
                returnType: null,
                isBound: true,
                entitySetPathExpression: null);
            actionBoundToEntityCollection.AddParameter("Param", entityCollection);
            container.AddActionImport(actionBoundToEntityCollection);

            // action bound to derived entity collection
            var actionBoundToDerivedEntityCollection = new EdmAction(
                "NS",
                "ActionBoundToDerivedEntityCollection",
                returnType: null,
                isBound: true,
                entitySetPathExpression: null);
            actionBoundToDerivedEntityCollection.AddParameter("Param", derivedEntityCollection);
            container.AddActionImport(actionBoundToDerivedEntityCollection);

            // ambiguos actions
            container.AddActionImport(new EdmAction("NS", "AmbiguousAction", returnType: null));
            container.AddActionImport(new EdmAction("NS", "AmbiguousAction", returnType: null));

            IEdmTypeReference returnType = new EdmPrimitiveTypeReference(
                EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), false);

            // non-bindable function
            container.AddFunctionImport(new EdmFunction("NS", "NonBindableFunction", returnType));

            // function bound to entity
            var functionBoundToEntity = new EdmFunction(
                "NS",
                "FunctionBoundToEntity",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            functionBoundToEntity.AddParameter("Param", _entityType);
            container.AddFunctionImport(functionBoundToEntity);

            // function bound to entity
            var functionBoundToDerivedEntity = new EdmFunction(
                "NS",
                "FunctionBoundToDerivedEntity",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            functionBoundToDerivedEntity.AddParameter("Param", _derivedEntityType);
            container.AddFunctionImport(functionBoundToDerivedEntity);

            // function bound to entity collection
            var functionBoundToEntityCollection = new EdmFunction(
                "NS",
                "FunctionBoundToEntityCollection",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            functionBoundToEntityCollection.AddParameter("Param", entityCollection);
            container.AddFunctionImport(functionBoundToEntityCollection);

            // function bound to derived entity collection
            var functionBoundToDerivedEntityCollection = new EdmFunction(
                "NS",
                "FunctionBoundToDerivedEntityCollection",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            functionBoundToDerivedEntityCollection.AddParameter("Param", derivedEntityCollection);
            container.AddFunctionImport(functionBoundToDerivedEntityCollection);

            return container;
        }