public static IEdmModel CreateModel(string ns) { EdmModel model = new EdmModel(); var defaultContainer = new EdmEntityContainer(ns, "DefaultContainer"); model.AddElement(defaultContainer); var addressType = new EdmComplexType(ns, "Address"); addressType.AddProperty(new EdmStructuralProperty(addressType, "Road", EdmCoreModel.Instance.GetString(false))); addressType.AddProperty(new EdmStructuralProperty(addressType, "City", EdmCoreModel.Instance.GetString(false))); model.AddElement(addressType); 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, "Address", new EdmComplexTypeReference(addressType, true))); personType.AddProperty(new EdmStructuralProperty(personType, "Descriptions", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false))))); model.AddElement(personType); var peopleSet = new EdmEntitySet(defaultContainer, "People", personType); defaultContainer.AddElement(peopleSet); var numberComboType = new EdmComplexType(ns, "NumberCombo"); numberComboType.AddProperty(new EdmStructuralProperty(numberComboType, "Small", EdmCoreModel.Instance.GetInt32(false))); numberComboType.AddProperty(new EdmStructuralProperty(numberComboType, "Middle", EdmCoreModel.Instance.GetInt64(false))); numberComboType.AddProperty(new EdmStructuralProperty(numberComboType, "Large", EdmCoreModel.Instance.GetDecimal(false))); model.AddElement(numberComboType); var productType = new EdmEntityType(ns, "Product"); var productIdProperty = new EdmStructuralProperty(productType, "ProductId", EdmCoreModel.Instance.GetInt32(false)); productType.AddProperty(productIdProperty); productType.AddKeys(new IEdmStructuralProperty[] { productIdProperty }); productType.AddProperty(new EdmStructuralProperty(productType, "Quantity", EdmCoreModel.Instance.GetInt64(false))); productType.AddProperty(new EdmStructuralProperty(productType, "LifeTimeInSeconds", EdmCoreModel.Instance.GetDecimal(false))); productType.AddProperty(new EdmStructuralProperty(productType, "TheCombo", new EdmComplexTypeReference(numberComboType, true))); productType.AddProperty(new EdmStructuralProperty(productType, "LargeNumbers", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetDecimal(false))))); model.AddElement(productType); var productsSet = new EdmEntitySet(defaultContainer, "Products", productType); defaultContainer.AddElement(productsSet); var productsProperty = personType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Products", Target = productType, TargetMultiplicity = EdmMultiplicity.Many }); peopleSet.AddNavigationTarget(productsProperty, productsSet); IEnumerable<EdmError> errors; model.Validate(out errors); return model; }
public void ValidationShouldFailOnNonXmlValidAnnotationWhichWontBeSerialized() { var model = new EdmModel(); var fredFlintstone = new EdmComplexType("Flintstones", "Fred"); fredFlintstone.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false)); model.AddElement(fredFlintstone); // Making the value of the annotation not an IEdmValue means that it won't be serialized out as an attribute annotation. // We should still fail on this anyway, since being strict now has fewer consequences than trying to introduce strictness later. model.SetAnnotationValue(fredFlintstone, "sap", "-content-version", 1); Assert.AreEqual(1, model.DirectValueAnnotations(fredFlintstone).Count(), "Wrong # of Annotations on {0}.", fredFlintstone); IEnumerable<EdmError> errors; model.Validate(out errors); Assert.AreEqual(1, errors.Count(), "Model expected to be invalid."); EdmError error = errors.Single(); Assert.AreEqual(error.ErrorCode, EdmErrorCode.InvalidName, "Unexpected error code"); Assert.AreEqual(error.ErrorMessage, "The specified name is not allowed: '-content-version'.", "Unexpected error message"); }
public void ValidateOpenComplexTypeSupported() { var ct = new StubEdmComplexType("NS1", "CT1") { IsOpen = true }; ct.Add(new EdmStructuralProperty(ct, "p1", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int16, true))); var model = new EdmModel(); model.AddElement(ct); IEnumerable<EdmError> errors; foreach (var v in new[] { Microsoft.OData.Edm.Library.EdmConstants.EdmVersionLatest }) { model.SetEdmVersion(v); model.Validate(out errors); Assert.AreEqual(0, errors.Count(), "No error should be returned"); } }
public void AnnotationNameWhichIsNotSimpleIdentifierShouldPassValidation() { var model = new EdmModel(); model.SetEdmVersion(Microsoft.OData.Edm.Library.EdmConstants.EdmVersion4); var fredFlintstone = new EdmComplexType("Flintstones", "Fred"); fredFlintstone.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false)); model.AddElement(fredFlintstone); // set the annotation name to a value which is valid XML, but not a valid SimpleIdentifier. model.SetAnnotationValue(fredFlintstone, "sap", "content-version", new EdmStringConstant(EdmCoreModel.Instance.GetString(false), "hello")); Assert.AreEqual(1, model.DirectValueAnnotations(fredFlintstone).Count(), "Wrong # of Annotations on {0}.", fredFlintstone); IEnumerable<EdmError> errors; model.Validate(out errors); Assert.AreEqual(0, errors.Count(), "Model expected to be valid."); }
public void ValidationShouldFailOnNonXmlValidAnnotation() { var model = new EdmModel(); var fredFlintstone = new EdmComplexType("Flintstones", "Fred"); fredFlintstone.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false)); model.AddElement(fredFlintstone); // Set annnotation which would be serialized as an attribute to be a value that is invalid per the xml spec. model.SetAnnotationValue(fredFlintstone, "sap", "-content-version", new EdmStringConstant(EdmCoreModel.Instance.GetString(false), "hello")); Assert.AreEqual(1, model.DirectValueAnnotations(fredFlintstone).Count(), "Wrong # of Annotations on {0}.", fredFlintstone); IEnumerable<EdmError> errors; model.Validate(out errors); Assert.AreEqual(1, errors.Count(), "Model expected to be invalid."); EdmError error = errors.Single(); Assert.AreEqual(error.ErrorCode, EdmErrorCode.InvalidName, "Unexpected error code"); Assert.AreEqual(error.ErrorMessage, "The specified name is not allowed: '-content-version'.", "Unexpected error message"); }
public void OneWayNavigationPropertyMultipleMappingTest() { EdmModel model = new EdmModel(); EdmEntityType t3 = new EdmEntityType("Bunk", "T3"); EdmStructuralProperty f31 = t3.AddStructuralProperty("F31", EdmCoreModel.Instance.GetString(false)); t3.AddKeys(f31); model.AddElement(t3); EdmEntityType t1 = new EdmEntityType("Bunk", "T1"); EdmStructuralProperty f11 = t1.AddStructuralProperty("F11", EdmCoreModel.Instance.GetString(false)); t1.AddKeys(f11); EdmNavigationProperty p101 = t1.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "P101", Target = t3, TargetMultiplicity = EdmMultiplicity.One }); model.AddElement(t1); EdmEntityContainer c1 = new EdmEntityContainer("Bunk", "Gunk"); EdmEntitySet E1a = c1.AddEntitySet("E1a", t1); EdmEntitySet E1b = c1.AddEntitySet("E1b", t1); EdmEntitySet E3 = c1.AddEntitySet("E3", t3); E1a.AddNavigationTarget(p101, E3); E1b.AddNavigationTarget(p101, E3); model.AddElement(c1); IEnumerable<EdmError> edmErrors; model.Validate(out edmErrors); Assert.IsTrue(!edmErrors.Any(), @"Enable multiple mappings for the same (silent) navigation property"); this.GetParserResult(this.GetSerializerResult(model)).Validate(out edmErrors); Assert.IsTrue(!edmErrors.Any(), @"Enable multiple mappings for the same (silent) navigation property"); }
public void TwoWayNavigationPropertyMultipleMappingInSingletonTest() { var model = new EdmModel(); var t3 = new EdmEntityType("Bunk", "T3"); var f31 = t3.AddStructuralProperty("F31", EdmCoreModel.Instance.GetString(false)); t3.AddKeys(f31); model.AddElement(t3); var t1 = new EdmEntityType("Bunk", "T1"); var f11 = t1.AddStructuralProperty("F11", EdmCoreModel.Instance.GetString(false)); t1.AddKeys(f11); var p101 = t1.AddBidirectionalNavigation ( new EdmNavigationPropertyInfo() { Name = "P101", Target = t3, TargetMultiplicity = EdmMultiplicity.One }, new EdmNavigationPropertyInfo() { Name = "P301", TargetMultiplicity = EdmMultiplicity.One } ); model.AddElement(t1); var c1 = new EdmEntityContainer("Bunk", "Gunk"); var E1a = c1.AddEntitySet("E1a", t1); var E1b = c1.AddSingleton("E1b", t1); var E3 = c1.AddSingleton("E3", t3); E1a.AddNavigationTarget(p101, E3); E1b.AddNavigationTarget(p101, E3); E3.AddNavigationTarget(p101.Partner, E1a); model.AddElement(c1); var expectedErrors = new EdmLibTestErrors() { { "(Microsoft.OData.Edm.Library.EdmSingleton)", EdmErrorCode.NavigationMappingMustBeBidirectional }, }; IEnumerable<EdmError> edmErrors; model.Validate(out edmErrors); this.CompareErrors(edmErrors, expectedErrors); }
public static IEdmModel CreateModel(string ns) { EdmModel model = new EdmModel(); var defaultContainer = new EdmEntityContainer(ns, "DefaultContainer"); model.AddElement(defaultContainer); var nameType = new EdmTypeDefinition(ns, "Name", EdmPrimitiveTypeKind.String); model.AddElement(nameType); var addressType = new EdmComplexType(ns, "Address"); addressType.AddProperty(new EdmStructuralProperty(addressType, "Road", new EdmTypeDefinitionReference(nameType, false))); addressType.AddProperty(new EdmStructuralProperty(addressType, "City", EdmCoreModel.Instance.GetString(false))); model.AddElement(addressType); 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", new EdmTypeDefinitionReference(nameType, false))); personType.AddProperty(new EdmStructuralProperty(personType, "LastName", new EdmTypeDefinitionReference(nameType, false))); personType.AddProperty(new EdmStructuralProperty(personType, "Address", new EdmComplexTypeReference(addressType, true))); personType.AddProperty(new EdmStructuralProperty(personType, "Descriptions", new EdmCollectionTypeReference(new EdmCollectionType(new EdmTypeDefinitionReference(nameType, false))))); model.AddElement(personType); var peopleSet = new EdmEntitySet(defaultContainer, "People", personType); defaultContainer.AddElement(peopleSet); var numberComboType = new EdmComplexType(ns, "NumberCombo"); numberComboType.AddProperty(new EdmStructuralProperty(numberComboType, "Small", model.GetUInt16(ns, false))); numberComboType.AddProperty(new EdmStructuralProperty(numberComboType, "Middle", model.GetUInt32(ns, false))); numberComboType.AddProperty(new EdmStructuralProperty(numberComboType, "Large", model.GetUInt64(ns, false))); model.AddElement(numberComboType); var productType = new EdmEntityType(ns, "Product"); var productIdProperty = new EdmStructuralProperty(productType, "ProductId", model.GetUInt16(ns, false)); productType.AddProperty(productIdProperty); productType.AddKeys(new IEdmStructuralProperty[] { productIdProperty }); productType.AddProperty(new EdmStructuralProperty(productType, "Quantity", model.GetUInt32(ns, false))); productType.AddProperty(new EdmStructuralProperty(productType, "NullableUInt32", model.GetUInt32(ns, true))); productType.AddProperty(new EdmStructuralProperty(productType, "LifeTimeInSeconds", model.GetUInt64(ns, false))); productType.AddProperty(new EdmStructuralProperty(productType, "TheCombo", new EdmComplexTypeReference(numberComboType, true))); productType.AddProperty(new EdmStructuralProperty(productType, "LargeNumbers", new EdmCollectionTypeReference(new EdmCollectionType(model.GetUInt64(ns, false))))); model.AddElement(productType); var productsSet = new EdmEntitySet(defaultContainer, "Products", productType); defaultContainer.AddElement(productsSet); //Bound Function: bound to entity, return defined type var getFullNameFunction = new EdmFunction(ns, "GetFullName", new EdmTypeDefinitionReference(nameType, false), true, null, false); getFullNameFunction.AddParameter("person", new EdmEntityTypeReference(personType, false)); getFullNameFunction.AddParameter("nickname", new EdmTypeDefinitionReference(nameType, false)); model.AddElement(getFullNameFunction); //Bound Action: bound to entity, return UInt64 var extendLifeTimeAction = new EdmAction(ns, "ExtendLifeTime", model.GetUInt64(ns, false), true, null); extendLifeTimeAction.AddParameter("product", new EdmEntityTypeReference(productType, false)); extendLifeTimeAction.AddParameter("seconds", model.GetUInt32(ns, false)); model.AddElement(extendLifeTimeAction); //UnBound Action: ResetDataSource var resetDataSourceAction = new EdmAction(ns, "ResetDataSource", null, false, null); model.AddElement(resetDataSourceAction); defaultContainer.AddActionImport(resetDataSourceAction); IEnumerable<EdmError> errors = null; model.Validate(out errors); return model; }
public void VerifyValidatorForNullError() { EdmModel model = new EdmModel(); model.AddElement(new ValidationTestModelBuilder.TestEdmAssociatedCheckableNullErrorElement()); IEnumerable<EdmError> edmError = null; model.Validate(out edmError); Assert.IsFalse(edmError.Any(), "The number of EdmErrors should be 0 if the null Error case means no error."); }
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 IEdmModel CreateModel(string ns) { EdmModel model = new EdmModel(); var defaultContainer = new EdmEntityContainer(ns, "DefaultContainer"); model.AddElement(defaultContainer); var orderDetail = new EdmComplexType(ns, "orderDetail"); orderDetail.AddProperty(new EdmStructuralProperty(orderDetail, "amount", EdmCoreModel.Instance.GetDecimal(false))); orderDetail.AddProperty(new EdmStructuralProperty(orderDetail, "quantity", EdmCoreModel.Instance.GetInt32(false))); model.AddElement(orderDetail); var billingType = new EdmEnumType(ns, "billingType", EdmPrimitiveTypeKind.Int64, false); billingType.AddMember("fund", new EdmIntegerConstant(0)); billingType.AddMember("refund", new EdmIntegerConstant(1)); billingType.AddMember("chargeback", new EdmIntegerConstant(2)); model.AddElement(billingType); var category = new EdmEnumType(ns, "category", true); category.AddMember("toy", new EdmIntegerConstant(1)); category.AddMember("food", new EdmIntegerConstant(2)); category.AddMember("cloth", new EdmIntegerConstant(4)); category.AddMember("drink", new EdmIntegerConstant(8)); category.AddMember("computer", new EdmIntegerConstant(16)); model.AddElement(category); var namedObject = new EdmEntityType(ns, "namedObject"); var idProperty = new EdmStructuralProperty(namedObject, "id", EdmCoreModel.Instance.GetInt32(false)); namedObject.AddProperty(idProperty); namedObject.AddKeys(idProperty); namedObject.AddProperty(new EdmStructuralProperty(namedObject, "name", EdmCoreModel.Instance.GetString(false))); model.AddElement(namedObject); var order = new EdmEntityType(ns, "order", namedObject); order.AddProperty(new EdmStructuralProperty(order, "description", EdmCoreModel.Instance.GetString(false))); order.AddProperty(new EdmStructuralProperty(order, "detail", new EdmComplexTypeReference(orderDetail, true))); order.AddProperty(new EdmStructuralProperty(order, "lineItems", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false))))); order.AddProperty(new EdmStructuralProperty(order, "categories", new EdmEnumTypeReference(category, false))); model.AddElement(order); var billingRecord = new EdmEntityType(ns, "billingRecord", namedObject); billingRecord.AddProperty(new EdmStructuralProperty(billingRecord, "amount", EdmCoreModel.Instance.GetDecimal(false))); billingRecord.AddProperty(new EdmStructuralProperty(billingRecord, "type", new EdmEnumTypeReference(billingType, false))); model.AddElement(billingRecord); var store = new EdmEntityType(ns, "store", namedObject); store.AddProperty(new EdmStructuralProperty(store, "address", EdmCoreModel.Instance.GetString(false))); model.AddElement(store); var orders = new EdmEntitySet(defaultContainer, "orders", order); defaultContainer.AddElement(orders); var billingRecords = new EdmEntitySet(defaultContainer, "billingRecords", billingRecord); defaultContainer.AddElement(billingRecords); var myStore = new EdmSingleton(defaultContainer, "myStore", store); defaultContainer.AddElement(myStore); var order2billingRecord = order.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "billingRecords", Target = billingRecord, TargetMultiplicity = EdmMultiplicity.Many }); ((EdmEntitySet)orders).AddNavigationTarget(order2billingRecord, billingRecords); IEnumerable<EdmError> errors = null; model.Validate(out errors); return model; }
public void TestEnumMemberReferencingExtraEnumType() { const string csdl = @"<?xml version=""1.0"" encoding=""utf-8""?> <edmx:Edmx Version=""4.0"" xmlns:edmx=""http://docs.oasis-open.org/odata/ns/edmx""> <edmx:DataServices> <Schema Namespace=""TestNS"" xmlns=""http://docs.oasis-open.org/odata/ns/edm""> <EntityType Name=""Person""> <Key> <PropertyRef Name=""Id"" /> </Key> <Property Name=""Id"" Type=""Edm.Int32"" Nullable=""false"" /> <Property Name=""Name"" Type=""Edm.String"" /> <Annotation Term=""TestNS.OutColor""> <EnumMember>TestNS2.Color/Blue TestNS2.Color/Cyan</EnumMember> </Annotation> </EntityType> <Term Name=""OutColor"" Type=""TestNS2.Color"" /> </Schema> <Schema Namespace=""TestNS2"" xmlns=""http://docs.oasis-open.org/odata/ns/edm""> <EnumType Name=""Color"" IsFlags=""true""> <Member Name=""Cyan"" Value=""1"" /> <Member Name=""Blue"" Value=""2"" /> </EnumType> </Schema> </edmx:DataServices> </edmx:Edmx>"; IEdmModel model; IEnumerable<EdmError> errors; IEnumerable<EdmError> validationErrors; #region try build model var edmModel = new EdmModel(); var personType = new EdmEntityType("TestNS", "Person"); edmModel.AddElement(personType); var pid = personType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, false); personType.AddKeys(pid); personType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); var colorType = new EdmEnumType("TestNS2", "Color", true); edmModel.AddElement(colorType); colorType.AddMember("Cyan", new EdmIntegerConstant(1)); colorType.AddMember("Blue", new EdmIntegerConstant(2)); var outColorTerm = new EdmTerm("TestNS", "OutColor", new EdmEnumTypeReference(colorType, true)); edmModel.AddElement(outColorTerm); var exp = new EdmEnumMemberExpression( new EdmEnumMember(colorType, "Blue", new EdmIntegerConstant(2)), new EdmEnumMember(colorType, "Cyan", new EdmIntegerConstant(1)) ); var annotation = new EdmAnnotation(personType, outColorTerm, exp); annotation.SetSerializationLocation(edmModel, EdmVocabularyAnnotationSerializationLocation.Inline); edmModel.SetVocabularyAnnotation(annotation); var stream = new MemoryStream(); Assert.IsFalse(edmModel.Validate(out errors)); using (var xw = XmlWriter.Create(stream, new XmlWriterSettings() { Indent = true })) { Assert.IsTrue(EdmxWriter.TryWriteEdmx(edmModel, xw, EdmxTarget.OData, out errors)); } stream.Seek(0, SeekOrigin.Begin); using (var sr = new StreamReader(stream)) { Assert.AreEqual(csdl, sr.ReadToEnd()); } #endregion Assert.IsTrue(EdmxReader.TryParse(XmlReader.Create(new StringReader(csdl)), out model, out errors), "parsed"); Assert.IsFalse(model.Validate(out validationErrors)); TestEnumMember(model); }
public void TestEdmValidator() { var model = new EdmModel(); IEnumerable<EdmError> actualErrors; model.Validate(out actualErrors); Assert.AreEqual(0, actualErrors.Count(), "Invalid error count."); this.VerifyThrowsException(typeof(ArgumentNullException), () => model.Validate((ValidationRuleSet)null, out actualErrors)); this.VerifyThrowsException(typeof(ArgumentNullException), () => model.Validate(new ValidationRuleSet(null), out actualErrors)); model.Validate(new ValidationRuleSet(new List<ValidationRule>()), out actualErrors); Assert.AreEqual(0, actualErrors.Count(), "Invalid error count."); }
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; }
private EdmModel CreateModelWithSillyNamespace() { var model = new EdmModel(); var customer = new EdmEntityType("Really.Way.Too.Long.Namespace.With.Lots.Of.Dots", "Customer"); var customerId = customer.AddStructuralProperty("CustomerID", EdmCoreModel.Instance.GetString(false)); customer.AddKeys(customerId); model.AddElement(customer); var title = new EdmTerm("Really.Way.Too.Long.Namespace.With.Lots.Of.Dots", "Title", EdmCoreModel.Instance.GetString(true)); model.AddElement(title); var integerId = new EdmTerm("Really.Way.Too.Long.Namespace.With.Lots.Of.Dots", "integerId", EdmCoreModel.Instance.GetString(true)); model.AddElement(integerId); var person = new EdmEntityType("Really.Way.Too.Long.Namespace.With.Lots.Of.Dots", "Person"); var Id = person.AddStructuralProperty("ID", EdmCoreModel.Instance.GetString(false)); person.AddKeys(Id); model.AddElement(person); var container = new EdmEntityContainer("Really.Way.Too.Long.Namespace.With.Lots.Of.Dots", "Container"); container.AddEntitySet("Customers", customer); model.AddElement(container); IEnumerable<EdmError> errors; Assert.IsTrue(model.Validate(out errors), "validate"); return model; }
private EdmModel CreateModel() { var model = new EdmModel(); var customer = new EdmEntityType("NS1", "Customer"); var customerId = new EdmStructuralProperty(customer, "CustomerID", EdmCoreModel.Instance.GetString(false)); customer.AddProperty(customerId); customer.AddKeys(customerId); model.AddElement(customer); var title = new EdmTerm("NS1", "Title", EdmCoreModel.Instance.GetString(true)); model.AddElement(title); var person = new EdmEntityType("NS1", "Person"); var Id = person.AddStructuralProperty("ID", EdmCoreModel.Instance.GetString(false)); person.AddKeys(Id); model.AddElement(person); var container = new EdmEntityContainer("NS1", "Container"); container.AddElement(new EdmEntitySet(container, "Customers", customer)); model.AddElement(container); IEnumerable<EdmError> errors; Assert.IsTrue(model.Validate(out errors), "validate"); return model; }