static InstanceAnnotationsReaderIntegrationTests() { EdmModel modelTmp = new EdmModel(); EntityType = new EdmEntityType("TestNamespace", "TestEntityType"); modelTmp.AddElement(EntityType); var keyProperty = new EdmStructuralProperty(EntityType, "ID", EdmCoreModel.Instance.GetInt32(false)); EntityType.AddKeys(new IEdmStructuralProperty[] { keyProperty }); EntityType.AddProperty(keyProperty); var resourceNavigationProperty = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ResourceNavigationProperty", Target = EntityType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }); var resourceSetNavigationProperty = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ResourceSetNavigationProperty", Target = EntityType, TargetMultiplicity = EdmMultiplicity.Many }); var defaultContainer = new EdmEntityContainer("TestNamespace", "DefaultContainer_sub"); modelTmp.AddElement(defaultContainer); EntitySet = new EdmEntitySet(defaultContainer, "TestEntitySet", EntityType); EntitySet.AddNavigationTarget(resourceNavigationProperty, EntitySet); EntitySet.AddNavigationTarget(resourceSetNavigationProperty, EntitySet); defaultContainer.AddElement(EntitySet); Singleton = new EdmSingleton(defaultContainer, "TestSingleton", EntityType); Singleton.AddNavigationTarget(resourceNavigationProperty, EntitySet); Singleton.AddNavigationTarget(resourceSetNavigationProperty, EntitySet); defaultContainer.AddElement(Singleton); ComplexType = new EdmComplexType("TestNamespace", "TestComplexType"); ComplexType.AddProperty(new EdmStructuralProperty(ComplexType, "StringProperty", EdmCoreModel.Instance.GetString(false))); modelTmp.AddElement(ComplexType); Model = TestUtils.WrapReferencedModelsToMainModel("TestNamespace", "DefaultContainer", modelTmp); }
static ExapndOptionFunctionalTests() { string namespaceA = "NS"; EdmModel edmModel = new EdmModel(); EdmEntityType type1 = new EdmEntityType(namespaceA, "T1"); EdmEntityType type2 = new EdmEntityType(namespaceA, "T2", type1); EdmEntityType type3 = new EdmEntityType(namespaceA, "T3", type2); EdmNavigationProperty nav21 = type2.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Nav21", ContainsTarget = false, Target = type1, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, }); EdmNavigationProperty nav22 = type2.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Nav22", ContainsTarget = false, Target = type2, TargetMultiplicity = EdmMultiplicity.One, }); EdmNavigationProperty nav23 = type2.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Nav23", ContainsTarget = false, Target = type3, TargetMultiplicity = EdmMultiplicity.Many, }); edmModel.AddElement(type1); edmModel.AddElement(type2); edmModel.AddElement(type3); EdmEntityContainer container = new EdmEntityContainer(namespaceA, "Con1"); var set1 = container.AddEntitySet(namespaceA, type1); var set2 = container.AddEntitySet(namespaceA, type2); var set3 = container.AddEntitySet(namespaceA, type3); edmModel.AddElement(container); set2.AddNavigationTarget(nav21, set1); set2.AddNavigationTarget(nav22, set2); set2.AddNavigationTarget(nav23, set3); Model = edmModel; T2Type = type2; T3Type = type3; T2Set = set2; T3Set = set3; }
public EdmDeltaModel(IEdmModel source, IEdmEntityType entityType, IEnumerable<string> propertyNames) { _source = source; _entityType = new EdmEntityType(entityType.Namespace, entityType.Name); foreach (var property in entityType.StructuralProperties()) { if (propertyNames.Contains(property.Name)) _entityType.AddStructuralProperty(property.Name, property.Type, property.DefaultValueString, property.ConcurrencyMode); } foreach (var property in entityType.NavigationProperties()) { if (propertyNames.Contains(property.Name)) { var navInfo = new EdmNavigationPropertyInfo() { ContainsTarget = property.ContainsTarget, DependentProperties = property.DependentProperties(), PrincipalProperties = property.PrincipalProperties(), Name = property.Name, OnDelete = property.OnDelete, Target = property.Partner != null ? property.Partner.DeclaringEntityType() : property.Type.TypeKind() == EdmTypeKind.Collection ? (property.Type.Definition as IEdmCollectionType).ElementType.Definition as IEdmEntityType : property.Type.TypeKind() == EdmTypeKind.Entity ? property.Type.Definition as IEdmEntityType : null, TargetMultiplicity = property.TargetMultiplicity(), }; _entityType.AddUnidirectionalNavigation(navInfo); } } }
private EdmModel GetModel() { EdmModel model = new EdmModel(); EdmEntityType edmEntityType = new EdmEntityType("NS", "Person"); edmEntityType.AddKeys(edmEntityType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); edmEntityType.AddStructuralProperty("Color", EdmPrimitiveTypeKind.String); edmEntityType.AddStructuralProperty("FA", EdmPrimitiveTypeKind.String); edmEntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MyDog", TargetMultiplicity = EdmMultiplicity.ZeroOrOne, Target = edmEntityType }); edmEntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MyCat", TargetMultiplicity = EdmMultiplicity.ZeroOrOne, Target = edmEntityType }); model.AddElement(edmEntityType); EdmEntityContainer container = new EdmEntityContainer("NS", "EntityContainer"); model.AddElement(container); container.AddEntitySet("People", edmEntityType); return model; }
public static IEdmModel MultipleSchemasWithDifferentNamespacesEdm() { var namespaces = new string[] { "FindMethodsTestModelBuilder.MultipleSchemasWithDifferentNamespaces.first", "FindMethodsTestModelBuilder.MultipleSchemasWithDifferentNamespaces.second" }; var model = new EdmModel(); foreach (var namespaceName in namespaces) { var entityType1 = new EdmEntityType(namespaceName, "validEntityType1"); entityType1.AddKeys(entityType1.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); var entityType2 = new EdmEntityType(namespaceName, "VALIDeNTITYtYPE2"); entityType2.AddKeys(entityType2.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); var entityType3 = new EdmEntityType(namespaceName, "VALIDeNTITYtYPE3"); entityType3.AddKeys(entityType3.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); entityType1.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo {Name = "Mumble", Target = entityType2, TargetMultiplicity = EdmMultiplicity.Many}); var complexType = new EdmComplexType(namespaceName, "ValidNameComplexType1"); complexType.AddStructuralProperty("aPropertyOne", new EdmComplexTypeReference(complexType, false)); model.AddElements(new IEdmSchemaElement[] { entityType1, entityType2, entityType3, complexType }); var function1 = new EdmFunction(namespaceName, "ValidFunction1", EdmCoreModel.Instance.GetSingle(false)); var function2 = new EdmFunction(namespaceName, "ValidFunction1", EdmCoreModel.Instance.GetSingle(false)); function2.AddParameter("param1", new EdmEntityTypeReference(entityType1, false)); var function3 = new EdmFunction(namespaceName, "ValidFunction1", EdmCoreModel.Instance.GetSingle(false)); function3.AddParameter("param1", EdmCoreModel.Instance.GetSingle(false)); model.AddElements(new IEdmSchemaElement[] {function1, function2, function3}); } return model; }
public void GetModel(EdmModel model, EdmEntityContainer container) { EdmEntityType student = new EdmEntityType("ns", "Student"); student.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); EdmStructuralProperty key = student.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32); student.AddKeys(key); model.AddElement(student); EdmEntitySet students = container.AddEntitySet("Students", student); EdmEntityType school = new EdmEntityType("ns", "School"); school.AddKeys(school.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); school.AddStructuralProperty("CreatedDay", EdmPrimitiveTypeKind.DateTimeOffset); model.AddElement(school); EdmEntitySet schools = container.AddEntitySet("Schools", student); EdmNavigationProperty schoolNavProp = student.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo { Name = "School", TargetMultiplicity = EdmMultiplicity.One, Target = school }); students.AddNavigationTarget(schoolNavProp, schools); _school = school; }
public static IEdmModel GetEdmModel() { EdmModel model = new EdmModel(); // Create and add product entity type. EdmEntityType product = new EdmEntityType("NS", "Product"); product.AddKeys(product.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); product.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); product.AddStructuralProperty("Price", EdmPrimitiveTypeKind.Double); model.AddElement(product); // Create and add category entity type. EdmEntityType category = new EdmEntityType("NS", "Category"); category.AddKeys(category.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); category.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); model.AddElement(category); // Set navigation from product to category. EdmNavigationPropertyInfo propertyInfo = new EdmNavigationPropertyInfo(); propertyInfo.Name = "Category"; propertyInfo.TargetMultiplicity = EdmMultiplicity.One; propertyInfo.Target = category; EdmNavigationProperty productCategory = product.AddUnidirectionalNavigation(propertyInfo); // Create and add entity container. EdmEntityContainer container = new EdmEntityContainer("NS", "DefaultContainer"); model.AddElement(container); // Create and add entity set for product and category. EdmEntitySet products = container.AddEntitySet("Products", product); EdmEntitySet categories = container.AddEntitySet("Categories", category); products.AddNavigationTarget(productCategory, categories); return model; }
private static void ReferentialConstraintDemo() { Console.WriteLine("ReferentialConstraintDemo"); EdmModel model = new EdmModel(); var customer = new EdmEntityType("ns", "Customer"); model.AddElement(customer); var customerId = customer.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, false); customer.AddKeys(customerId); var address = new EdmComplexType("ns", "Address"); model.AddElement(address); var code = address.AddStructuralProperty("gid", EdmPrimitiveTypeKind.Guid); customer.AddStructuralProperty("addr", new EdmComplexTypeReference(address, true)); var order = new EdmEntityType("ns", "Order"); model.AddElement(order); var oId = order.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, false); order.AddKeys(oId); var orderCustomerId = order.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32, false); var nav = new EdmNavigationPropertyInfo() { Name = "NavCustomer", Target = customer, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { orderCustomerId }, PrincipalProperties = new[] { customerId } }; order.AddUnidirectionalNavigation(nav); ShowModel(model); }
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 static IEdmModel CreateServiceEdmModel(string ns) { EdmModel model = new EdmModel(); var defaultContainer = new EdmEntityContainer(ns, "PerfInMemoryContainer"); model.AddElement(defaultContainer); 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, "Age", EdmCoreModel.Instance.GetInt32(false))); model.AddElement(personType); var simplePersonSet = new EdmEntitySet(defaultContainer, "SimplePeopleSet", personType); defaultContainer.AddElement(simplePersonSet); var largetPersonSet = new EdmEntitySet(defaultContainer, "LargePeopleSet", personType); defaultContainer.AddElement(largetPersonSet); 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 companyType = new EdmEntityType(ns, "Company"); var companyId = new EdmStructuralProperty(companyType, "CompanyID", EdmCoreModel.Instance.GetInt32(false)); companyType.AddProperty(companyId); companyType.AddKeys(companyId); companyType.AddProperty(new EdmStructuralProperty(companyType, "Name", EdmCoreModel.Instance.GetString(true))); companyType.AddProperty(new EdmStructuralProperty(companyType, "Address", new EdmComplexTypeReference(addressType, true))); companyType.AddProperty(new EdmStructuralProperty(companyType, "Revenue", EdmCoreModel.Instance.GetInt32(false))); model.AddElement(companyType); var companySet = new EdmEntitySet(defaultContainer, "CompanySet", companyType); defaultContainer.AddElement(companySet); var companyEmployeeNavigation = companyType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Employees", Target = personType, TargetMultiplicity = EdmMultiplicity.Many }); companySet.AddNavigationTarget(companyEmployeeNavigation, largetPersonSet); // ResetDataSource var resetDataSourceAction = new EdmAction(ns, "ResetDataSource", null, false, null); model.AddElement(resetDataSourceAction); defaultContainer.AddActionImport(resetDataSourceAction); return model; }
static DeltaLinkWriterIntegrationTests() { Model = new EdmModel(); EntityType = new EdmEntityType("TestNamespace", "TestEntityType"); Model.AddElement(EntityType); var keyProperty = new EdmStructuralProperty(EntityType, "ID", EdmCoreModel.Instance.GetInt32(false)); EntityType.AddKeys(new IEdmStructuralProperty[] { keyProperty }); EntityType.AddProperty(keyProperty); var resourceNavigationProperty = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ResourceNavigationProperty", Target = EntityType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }); var resourceSetNavigationProperty = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ResourceSetNavigationProperty", Target = EntityType, TargetMultiplicity = EdmMultiplicity.Many }); var defaultContainer = new EdmEntityContainer("TestNamespace", "DefaultContainer"); Model.AddElement(defaultContainer); EntitySet = new EdmEntitySet(defaultContainer, "TestEntitySet", EntityType); EntitySet.AddNavigationTarget(resourceNavigationProperty, EntitySet); EntitySet.AddNavigationTarget(resourceSetNavigationProperty, EntitySet); defaultContainer.AddElement(EntitySet); }
public SegmentKeyHandlerTests() { var typeWithStringKey = new EdmEntityType("NS.Foo", "TypeWithStringKey"); var originalType = new EdmEntityType("NS.Foo", "SourceType"); var keyProp = typeWithStringKey.AddStructuralProperty("KeyProp", EdmPrimitiveTypeKind.String); typeWithStringKey.AddKeys(keyProp); var multipleResultsWithSingleKeyNavProp = originalType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "NavProp", Target = typeWithStringKey, TargetMultiplicity = EdmMultiplicity.Many }); this.singleResultSegmentWithSingleKey = new NavigationPropertySegment(HardCodedTestModel.GetPersonMyDogNavProp(), null) { SingleResult = true }; this.multipleResultSegmentWithSingleKey = new NavigationPropertySegment(multipleResultsWithSingleKeyNavProp, null) { SingleResult = false }; this.multipleResultSegmentWithCompositeKey = new NavigationPropertySegment(HardCodedTestModel.GetPersonMyLionsNavProp(), null) { SingleResult = false }; }
static ODataEntryMetadataContextTest() { ActualEntityType = new EdmEntityType("ns", "TypeName"); ActualEntityType.AddKeys(new IEdmStructuralProperty[] {ActualEntityType.AddStructuralProperty("ID2", EdmPrimitiveTypeKind.Int32), ActualEntityType.AddStructuralProperty("ID3", EdmPrimitiveTypeKind.Int32)}); ActualEntityType.AddStructuralProperty("Name2", EdmCoreModel.Instance.GetString(isNullable:true), /*defaultValue*/null, EdmConcurrencyMode.Fixed); ActualEntityType.AddStructuralProperty("Name3", EdmCoreModel.Instance.GetString(isNullable: true), /*defaultValue*/null, EdmConcurrencyMode.Fixed); ActualEntityType.AddStructuralProperty("StreamProp1", EdmPrimitiveTypeKind.Stream); ActualEntityType.AddStructuralProperty("StreamProp2", EdmPrimitiveTypeKind.Stream); var navProp1 = ActualEntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Target = ActualEntityType, TargetMultiplicity = EdmMultiplicity.Many, Name = "NavProp1" }); var navProp2 = ActualEntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Target = ActualEntityType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, Name = "NavProp2" }); var container = new EdmEntityContainer("Namespace", "Container"); EdmEntitySet entitySet = container.AddEntitySet("EntitySet", ActualEntityType); entitySet.AddNavigationTarget(navProp1, entitySet); entitySet.AddNavigationTarget(navProp2, entitySet); Action1 = new EdmAction("Namespace", "Action1", null, true /*isBound*/, null /*entitySetPath*/); Action2 = new EdmAction("Namespace", "Action2", null, true /*isBound*/, null /*entitySetPath*/); ActionImport1 = new EdmActionImport(container, "ActionImport1", Action1); ActionImport2 = new EdmActionImport(container, "ActionImport2", Action2); Function1 = new EdmFunction("Namespace", "Function1", EdmCoreModel.Instance.GetString(isNullable: true), true /*isBound*/, null /*entitySetPath*/, true /*isComposable*/); Function2 = new EdmFunction("Namespace", "Function2", EdmCoreModel.Instance.GetString(isNullable: true), true /*isBound*/, null /*entitySetPath*/, true /*isComposable*/); FunctionImport1 = new EdmFunctionImport(container, "FunctionImport1", Function1); FunctionImport2 = new EdmFunctionImport(container, "FunctionImport2", Function2); }
public void Initialize() { this.edmModel = new EdmModel(); this.defaultContainer = new EdmEntityContainer("TestModel", "DefaultContainer"); this.edmModel.AddElement(this.defaultContainer); this.townType = new EdmEntityType("TestModel", "Town"); this.edmModel.AddElement(townType); EdmStructuralProperty townIdProperty = townType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(/*isNullable*/false)); townType.AddKeys(townIdProperty); townType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(/*isNullable*/false)); townType.AddStructuralProperty("Size", EdmCoreModel.Instance.GetInt32(/*isNullable*/false)); this.cityType = new EdmEntityType("TestModel", "City", this.townType); cityType.AddStructuralProperty("Photo", EdmCoreModel.Instance.GetStream(/*isNullable*/false)); this.edmModel.AddElement(cityType); this.districtType = new EdmEntityType("TestModel", "District"); EdmStructuralProperty districtIdProperty = districtType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(/*isNullable*/false)); districtType.AddKeys(districtIdProperty); districtType.AddStructuralProperty("Zip", EdmCoreModel.Instance.GetInt32(/*isNullable*/false)); districtType.AddStructuralProperty("Thumbnail", EdmCoreModel.Instance.GetStream(/*isNullable*/false)); this.edmModel.AddElement(districtType); cityType.AddBidirectionalNavigation( new EdmNavigationPropertyInfo { Name = "Districts", Target = districtType, TargetMultiplicity = EdmMultiplicity.Many }, new EdmNavigationPropertyInfo { Name = "City", Target = cityType, TargetMultiplicity = EdmMultiplicity.One }); this.defaultContainer.AddEntitySet("Cities", cityType); this.defaultContainer.AddEntitySet("Districts", districtType); this.metropolisType = new EdmEntityType("TestModel", "Metropolis", this.cityType); this.metropolisType.AddStructuralProperty("MetropolisStream", EdmCoreModel.Instance.GetStream(/*isNullable*/false)); this.edmModel.AddElement(metropolisType); metropolisType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MetropolisNavigation", Target = districtType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }); this.action = new EdmAction("TestModel", "Action", new EdmEntityTypeReference(this.cityType, true)); this.action.AddParameter("Param", EdmCoreModel.Instance.GetInt32(false)); this.edmModel.AddElement(action); this.actionImport = new EdmActionImport(this.defaultContainer, "Action", action); this.actionConflictingWithPropertyName = new EdmAction("TestModel", "Zip", new EdmEntityTypeReference(this.districtType, true)); this.actionConflictingWithPropertyName.AddParameter("Param", EdmCoreModel.Instance.GetInt32(false)); this.edmModel.AddElement(actionConflictingWithPropertyName); this.actionImportConflictingWithPropertyName = new EdmActionImport(this.defaultContainer, "Zip", actionConflictingWithPropertyName); this.openType = new EdmEntityType("TestModel", "OpenCity", this.cityType, false, true); }
public static IEdmModel SimpleCustomerOrderModel() { var model = new EdmModel(); var customerType = new EdmEntityType("Default", "Customer"); customerType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32); customerType.AddStructuralProperty("FirstName", EdmPrimitiveTypeKind.String); customerType.AddStructuralProperty("LastName", EdmPrimitiveTypeKind.String); IEdmTypeReference primitiveTypeReference = EdmCoreModel.Instance.GetPrimitive( EdmPrimitiveTypeKind.String, isNullable: true); customerType.AddStructuralProperty( "City", primitiveTypeReference, defaultValue: null, concurrencyMode: EdmConcurrencyMode.Fixed); model.AddElement(customerType); var orderType = new EdmEntityType("Default", "Order"); orderType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32); orderType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); orderType.AddStructuralProperty("Shipment", EdmPrimitiveTypeKind.String); model.AddElement(orderType); var addressType = new EdmComplexType("Default", "Address"); addressType.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String); addressType.AddStructuralProperty("City", EdmPrimitiveTypeKind.String); addressType.AddStructuralProperty("State", EdmPrimitiveTypeKind.String); addressType.AddStructuralProperty("Country", EdmPrimitiveTypeKind.String); addressType.AddStructuralProperty("ZipCode", EdmPrimitiveTypeKind.String); model.AddElement(addressType); // Add navigations customerType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Orders", Target = orderType, TargetMultiplicity = EdmMultiplicity.Many }); orderType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Customer", Target = customerType, TargetMultiplicity = EdmMultiplicity.One }); // Add Entity set var container = new EdmEntityContainer("Default", "Container"); var customerSet = container.AddEntitySet("Customers", customerType); var orderSet = container.AddEntitySet("Orders", orderType); customerSet.AddNavigationTarget(customerType.NavigationProperties().Single(np => np.Name == "Orders"), orderSet); orderSet.AddNavigationTarget(orderType.NavigationProperties().Single(np => np.Name == "Customer"), customerSet); NavigationSourceLinkBuilderAnnotation linkAnnotation = new MockNavigationSourceLinkBuilderAnnotation(); model.SetNavigationSourceLinkBuilder(customerSet, linkAnnotation); model.SetNavigationSourceLinkBuilder(orderSet, linkAnnotation); model.AddElement(container); return model; }
public void Init() { this.clientEdmModel = new ClientEdmModel(ODataProtocolVersion.V4); this.entityDescriptor = new EntityDescriptor(this.clientEdmModel) { Entity = new Customer() }; var serverType = new EdmEntityType("FQ.NS", "MyServerType"); serverType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Navigation", Target = serverType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }); this.serverTypeName = ((IEdmSchemaElement)serverType).FullName(); var serverContainer = new EdmEntityContainer("FQ.NS", "MyContainer"); this.serverEntitySet = serverContainer.AddEntitySet("MyEntitySet", serverType); var serverModel = new EdmModel(); serverModel.AddElement(serverType); serverModel.AddElement(serverContainer); this.ctx = new DataServiceContext(new Uri("http://temp.org/"), ODataProtocolVersion.V4, this.clientEdmModel); this.ctx.Format.UseJson(serverModel); this.testSubject = new RequestInfo(ctx); }
public JsonLightTypeResolverTests() { this.serverModel = new EdmModel(); var serverEntityType = new EdmEntityType("Server.Name.Space", "EntityType"); serverEntityType.AddKeys(serverEntityType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); var parentType = new EdmEntityType("Server.Name.Space", "Parent"); this.serverModel.AddElement(serverEntityType); this.serverModel.AddElement(parentType); var serverComplexType = new EdmComplexType("Server.Name.Space", "ComplexType"); serverComplexType.AddStructuralProperty("Number", EdmPrimitiveTypeKind.Int32); this.serverModel.AddElement(serverComplexType); var entityContainer = new EdmEntityContainer("Fake", "Container"); this.serverModel.AddElement(entityContainer); entityContainer.AddEntitySet("Entities", serverEntityType); entityContainer.AddEntitySet("Parents", parentType); parentType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Navigation", Target = serverEntityType, TargetMultiplicity = EdmMultiplicity.Many }); }
private IEdmModel BuildPayloadOrderTestModel() { var model = new EdmModel(); var otherType = new EdmEntityType(DefaultNamespaceName, "OtherType"); otherType.AddKeys(otherType.AddStructuralProperty("ID", Int32TypeRef)); model.AddElement(otherType); var allInType = new EdmEntityType(DefaultNamespaceName, "AllInType", null, false, false, true); allInType.AddKeys(allInType.AddStructuralProperty("ID", Int32TypeRef)); allInType.AddStructuralProperty("Name", StringTypeRef); allInType.AddStructuralProperty("Description", StringTypeRef); allInType.AddStructuralProperty("StreamProperty", EdmPrimitiveTypeKind.Stream, isNullable: false); allInType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "NavProp", Target = otherType, TargetMultiplicity = EdmMultiplicity.Many }); model.AddElement(allInType); var container = new EdmEntityContainer(DefaultNamespaceName, "DefaultContainer"); container.AddEntitySet("OtherType", otherType); container.AddEntitySet("AllInType", allInType); model.AddElement(container); return model; }
public void GetModel(EdmModel model, EdmEntityContainer container) { EdmEntityType product = new EdmEntityType("ns", "Product"); product.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); EdmStructuralProperty key = product.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32); product.AddKeys(key); model.AddElement(product); EdmEntitySet products = container.AddEntitySet("Products", product); EdmEntityType detailInfo = new EdmEntityType("ns", "DetailInfo"); detailInfo.AddKeys(detailInfo.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); detailInfo.AddStructuralProperty("Title", EdmPrimitiveTypeKind.String); model.AddElement(detailInfo); EdmEntitySet detailInfos = container.AddEntitySet("DetailInfos", product); EdmNavigationProperty detailInfoNavProp = product.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo { Name = "DetailInfo", TargetMultiplicity = EdmMultiplicity.One, Target = detailInfo }); products.AddNavigationTarget(detailInfoNavProp, detailInfos); }
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; }
public static IEdmModel TaupoDefaultModelEdm() { var model = new EdmModel(); #region TaupoDefault Model code var phoneType = new EdmComplexType("NS1", "Phone"); phoneType.AddStructuralProperty("PhoneNumber", EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: 16, isUnicode: false, isNullable: false)); phoneType.AddStructuralProperty("Extension", EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: 16, isUnicode: false, isNullable: true)); model.AddElement(phoneType); var phoneTypeReference = new EdmComplexTypeReference(phoneType, false); var contactDetailsType = new EdmComplexType("NS1", "ContactDetails"); contactDetailsType.AddStructuralProperty("Email", EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: 32, isUnicode: false, isNullable: false)); contactDetailsType.AddStructuralProperty("HomePhone", phoneTypeReference); contactDetailsType.AddStructuralProperty("WorkPhone", phoneTypeReference); contactDetailsType.AddStructuralProperty("MobilePhone", phoneTypeReference); model.AddElement(contactDetailsType); var contactDetailsTypeReference = new EdmComplexTypeReference(contactDetailsType, false); var concurrencyInfoType = new EdmComplexType("NS1", "ConcurrencyInfo"); concurrencyInfoType.AddStructuralProperty("Token", EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: 20, isUnicode: false, isNullable: false), string.Empty, EdmConcurrencyMode.Fixed); concurrencyInfoType.AddStructuralProperty("QueriedDateTimeOffset", EdmCoreModel.Instance.GetDateTimeOffset(true)); model.AddElement(concurrencyInfoType); var concurrencyInfoTypeReference = new EdmComplexTypeReference(concurrencyInfoType, false); var auditInfoType = new EdmComplexType("NS1", "AuditInfo"); auditInfoType.AddStructuralProperty("ModifiedDate", EdmPrimitiveTypeKind.DateTimeOffset); auditInfoType.AddStructuralProperty("ModifiedBy", EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: 50, isUnicode: false, isNullable: false)); auditInfoType.AddStructuralProperty("Concurrency", new EdmComplexTypeReference(concurrencyInfoType, false)); model.AddElement(auditInfoType); var auditInfoTypeReference = new EdmComplexTypeReference(auditInfoType, false); var dimensionsType = new EdmComplexType("NS1", "Dimensions"); dimensionsType.AddStructuralProperty("Width", EdmCoreModel.Instance.GetDecimal(10, 3, false)); dimensionsType.AddStructuralProperty("Height", EdmCoreModel.Instance.GetDecimal(10, 3, false)); dimensionsType.AddStructuralProperty("Depth", EdmCoreModel.Instance.GetDecimal(10, 3, false)); model.AddElement(dimensionsType); var dimensionsTypeReference = new EdmComplexTypeReference(dimensionsType, false); var suspiciousActivityType = new EdmEntityType("NS1", "SuspiciousActivity"); suspiciousActivityType.AddKeys(suspiciousActivityType.AddStructuralProperty("SuspiciousActivityId", EdmPrimitiveTypeKind.Int32, false)); suspiciousActivityType.AddStructuralProperty("Activity", EdmPrimitiveTypeKind.String); model.AddElement(suspiciousActivityType); var messageType = new EdmEntityType("NS1", "Message"); var fromUsername = messageType.AddStructuralProperty("FromUsername", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 50, isUnicode: false)); messageType.AddKeys(messageType.AddStructuralProperty("MessageId", EdmPrimitiveTypeKind.Int32, false), fromUsername); var toUsername = messageType.AddStructuralProperty("ToUsername", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 50, isUnicode: false)); messageType.AddStructuralProperty("Sent", EdmPrimitiveTypeKind.DateTimeOffset); messageType.AddStructuralProperty("Subject", EdmPrimitiveTypeKind.String); messageType.AddStructuralProperty("Body", EdmCoreModel.Instance.GetString(true)); messageType.AddStructuralProperty("IsRead", EdmCoreModel.Instance.GetBoolean(false)); model.AddElement(messageType); var loginType = new EdmEntityType("NS1", "Login"); loginType.AddKeys(loginType.AddStructuralProperty("Username", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 50, isUnicode: false))); var loginCustomerIdProperty = loginType.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32, false); model.AddElement(loginType); var loginSentMessages = new EdmNavigationPropertyInfo { Name = "SentMessages", Target = messageType, TargetMultiplicity = EdmMultiplicity.Many }; var messageSender = new EdmNavigationPropertyInfo { Name = "Sender", Target = loginType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { fromUsername }, PrincipalProperties = loginType.Key() }; loginType.AddBidirectionalNavigation(loginSentMessages, messageSender); var loginReceivedMessages = new EdmNavigationPropertyInfo { Name = "ReceivedMessages", Target = messageType, TargetMultiplicity = EdmMultiplicity.Many }; var messageRecipient = new EdmNavigationPropertyInfo { Name = "Recipient", Target = loginType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { fromUsername }, PrincipalProperties = loginType.Key() }; loginType.AddBidirectionalNavigation(loginReceivedMessages, messageRecipient); var loginSuspiciousActivity = new EdmNavigationPropertyInfo { Name = "SuspiciousActivity", Target = suspiciousActivityType, TargetMultiplicity = EdmMultiplicity.Many }; loginType.AddUnidirectionalNavigation(loginSuspiciousActivity); var lastLoginType = new EdmEntityType("NS1", "LastLogin"); var userNameProperty = lastLoginType.AddStructuralProperty("Username", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 50, isUnicode: false)); lastLoginType.AddKeys(userNameProperty); lastLoginType.AddStructuralProperty("LoggedIn", EdmPrimitiveTypeKind.DateTimeOffset); lastLoginType.AddStructuralProperty("LoggedOut", EdmCoreModel.Instance.GetDateTimeOffset(true)); model.AddElement(lastLoginType); var loginLastLogin = new EdmNavigationPropertyInfo { Name = "LastLogin", Target = lastLoginType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }; var lastLoginLogin = new EdmNavigationPropertyInfo { Name = "Login", Target = loginType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { userNameProperty }, PrincipalProperties = loginType.Key() }; lastLoginType.AddBidirectionalNavigation(lastLoginLogin, loginLastLogin); var orderType = new EdmEntityType("NS1", "Order"); orderType.AddKeys(orderType.AddStructuralProperty("OrderId", EdmPrimitiveTypeKind.Int32, false)); var orderCustomerId = orderType.AddStructuralProperty("CustomerId", EdmCoreModel.Instance.GetInt32(true)); orderType.AddStructuralProperty("Concurrency", concurrencyInfoTypeReference); model.AddElement(orderType); var loginOrders = new EdmNavigationPropertyInfo { Name = "Orders", Target = orderType, TargetMultiplicity = EdmMultiplicity.Many }; var orderLogin = new EdmNavigationPropertyInfo { Name = "Login", Target = loginType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }; orderType.AddBidirectionalNavigation(orderLogin, loginOrders); var customerInfoType = new EdmEntityType("NS1", "CustomerInfo"); customerInfoType.AddKeys(customerInfoType.AddStructuralProperty("CustomerInfoId", EdmPrimitiveTypeKind.Int32, false)); customerInfoType.AddStructuralProperty("Information", EdmPrimitiveTypeKind.String); model.AddElement(customerInfoType); var customerType = new EdmEntityType("NS1", "Customer"); var customerIdProperty = customerType.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32, false); customerType.AddKeys(customerIdProperty); customerType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: 100, isUnicode: false, isNullable: false)); customerType.AddStructuralProperty("ContactInfo", contactDetailsTypeReference); model.AddElement(customerType); var customerOrders = new EdmNavigationPropertyInfo { Name = "Orders", Target = orderType, TargetMultiplicity = EdmMultiplicity.Many, }; var orderCustomer = new EdmNavigationPropertyInfo { Name = "Customer", Target = customerType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, DependentProperties = new[] { orderCustomerId }, PrincipalProperties = customerType.Key() }; customerType.AddBidirectionalNavigation(customerOrders, orderCustomer); var customerLogins = new EdmNavigationPropertyInfo { Name = "Logins", Target = loginType, TargetMultiplicity = EdmMultiplicity.Many, }; var loginCustomer = new EdmNavigationPropertyInfo { Name = "Customer", Target = customerType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { loginCustomerIdProperty }, PrincipalProperties = customerType.Key() }; customerType.AddBidirectionalNavigation(customerLogins, loginCustomer); var customerHusband = new EdmNavigationPropertyInfo { Name = "Husband", Target = customerType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }; var customerWife = new EdmNavigationPropertyInfo { Name = "Wife", Target = customerType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }; customerType.AddBidirectionalNavigation(customerHusband, customerWife); var customerInfo = new EdmNavigationPropertyInfo { Name = "CustomerInfo", Target = customerInfoType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }; customerType.AddUnidirectionalNavigation(customerInfo); var productType = new EdmEntityType("NS1", "Product"); productType.AddKeys(productType.AddStructuralProperty("ProductId", EdmPrimitiveTypeKind.Int32, false)); productType.AddStructuralProperty("Description", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: true, maxLength: 1000, isUnicode: false)); productType.AddStructuralProperty("Dimensions", dimensionsTypeReference); productType.AddStructuralProperty("BaseConcurrency", EdmCoreModel.Instance.GetString(false), string.Empty, EdmConcurrencyMode.Fixed); productType.AddStructuralProperty("ComplexConcurrency", concurrencyInfoTypeReference); productType.AddStructuralProperty("NestedComplexConcurrency", auditInfoTypeReference); model.AddElement(productType); var barCodeType = new EdmEntityType("NS1", "Barcode"); barCodeType.AddKeys(barCodeType.AddStructuralProperty("Code", EdmCoreModel.Instance.GetBinary(isUnbounded: false, isNullable: false, maxLength: 50))); var barCodeProductIdProperty = barCodeType.AddStructuralProperty("ProductId", EdmPrimitiveTypeKind.Int32, false); barCodeType.AddStructuralProperty("Text", EdmPrimitiveTypeKind.String); model.AddElement(barCodeType); var productBarCodes = new EdmNavigationPropertyInfo { Name = "Barcodes", Target = barCodeType, TargetMultiplicity = EdmMultiplicity.Many }; var barCodeProduct = new EdmNavigationPropertyInfo { Name = "Product", Target = productType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { barCodeProductIdProperty }, PrincipalProperties = productType.Key() }; barCodeType.AddBidirectionalNavigation(barCodeProduct, productBarCodes); var incorrectScanType = new EdmEntityType("NS1", "IncorrectScan"); incorrectScanType.AddKeys(incorrectScanType.AddStructuralProperty("IncorrectScanId", EdmPrimitiveTypeKind.Int32, false)); var expectedCodeProperty = incorrectScanType.AddStructuralProperty("ExpectedCode", EdmCoreModel.Instance.GetBinary(isUnbounded: false, isNullable: false, maxLength: 50)); var actualCodeProperty = incorrectScanType.AddStructuralProperty("ActualCode", EdmCoreModel.Instance.GetBinary(isUnbounded: false, isNullable: true, maxLength: 50)); incorrectScanType.AddStructuralProperty("ScanDate", EdmPrimitiveTypeKind.DateTimeOffset); incorrectScanType.AddStructuralProperty("Details", EdmPrimitiveTypeKind.String); model.AddElement(incorrectScanType); var barCodeIncorrectScan = new EdmNavigationPropertyInfo { Name = "BadScans", Target = incorrectScanType, TargetMultiplicity = EdmMultiplicity.Many }; var incorrectScanExpectedBarCode = new EdmNavigationPropertyInfo { Name = "ExpectedBarcode", Target = barCodeType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { expectedCodeProperty }, PrincipalProperties = barCodeType.Key() }; incorrectScanType.AddBidirectionalNavigation(incorrectScanExpectedBarCode, barCodeIncorrectScan); var actualBarcode = new EdmNavigationPropertyInfo { Name = "ActualBarcode", Target = barCodeType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, DependentProperties = new[] { actualCodeProperty }, PrincipalProperties = barCodeType.Key() }; incorrectScanType.AddUnidirectionalNavigation(actualBarcode); var barCodeDetailType = new EdmEntityType("NS1", "BarcodeDetail"); var codeProperty = barCodeDetailType.AddStructuralProperty("Code", EdmCoreModel.Instance.GetBinary(isUnbounded: false, isNullable: false, maxLength: 50)); barCodeDetailType.AddKeys(codeProperty); barCodeDetailType.AddStructuralProperty("RegisteredTo", EdmPrimitiveTypeKind.String); model.AddElement(barCodeDetailType); var barCodeDetail = new EdmNavigationPropertyInfo { Name = "Detail", Target = barCodeDetailType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = barCodeType.Key(), PrincipalProperties = barCodeDetailType.Key() }; barCodeType.AddUnidirectionalNavigation(barCodeDetail); var resolutionType = new EdmEntityType("NS1", "Resolution"); resolutionType.AddKeys(resolutionType.AddStructuralProperty("ResolutionId", EdmPrimitiveTypeKind.Int32, false)); resolutionType.AddStructuralProperty("Details", EdmPrimitiveTypeKind.String); model.AddElement(resolutionType); var complaintType = new EdmEntityType("NS1", "Complaint"); complaintType.AddKeys(complaintType.AddStructuralProperty("ComplaintId", EdmPrimitiveTypeKind.Int32, false)); var complaintCustomerId = complaintType.AddStructuralProperty("CustomerId", EdmCoreModel.Instance.GetInt32(true)); complaintType.AddStructuralProperty("Logged", EdmPrimitiveTypeKind.DateTimeOffset); complaintType.AddStructuralProperty("Details", EdmPrimitiveTypeKind.String); model.AddElement(complaintType); var complaintCustomer = new EdmNavigationPropertyInfo { Name = "Customer", Target = customerType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, DependentProperties = new[] { complaintCustomerId }, PrincipalProperties = customerType.Key() }; complaintType.AddUnidirectionalNavigation(complaintCustomer); var complaintResolution = new EdmNavigationPropertyInfo { Name = "Resolution", Target = resolutionType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }; var resolutionComplaint = new EdmNavigationPropertyInfo { Name = "Complaint", Target = complaintType, TargetMultiplicity = EdmMultiplicity.One }; complaintType.AddBidirectionalNavigation(complaintResolution, resolutionComplaint); var smartCardType = new EdmEntityType("NS1", "SmartCard"); var smartCardUsername = smartCardType.AddStructuralProperty("Username", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 50, isUnicode: false)); smartCardType.AddKeys(smartCardUsername); smartCardType.AddStructuralProperty("CardSerial", EdmPrimitiveTypeKind.String); smartCardType.AddStructuralProperty("Issued", EdmPrimitiveTypeKind.DateTimeOffset); model.AddElement(smartCardType); var smartCardLogin = new EdmNavigationPropertyInfo { Name = "Login", Target = loginType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { smartCardUsername }, PrincipalProperties = loginType.Key() }; smartCardType.AddUnidirectionalNavigation(smartCardLogin); var smartCardLastLogin = new EdmNavigationPropertyInfo { Name = "LastLogin", Target = lastLoginType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }; smartCardType.AddUnidirectionalNavigation(smartCardLastLogin); var rsaTokenType = new EdmEntityType("NS1", "RSAToken"); rsaTokenType.AddKeys(rsaTokenType.AddStructuralProperty("Serial", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 20, isUnicode: false))); rsaTokenType.AddStructuralProperty("Issued", EdmPrimitiveTypeKind.DateTimeOffset); model.AddElement(rsaTokenType); var rsaTokenLogin = new EdmNavigationPropertyInfo { Name = "Login", Target = loginType, TargetMultiplicity = EdmMultiplicity.One }; rsaTokenType.AddUnidirectionalNavigation(rsaTokenLogin); var passwordResetType = new EdmEntityType("NS1", "PasswordReset"); passwordResetType.AddKeys(passwordResetType.AddStructuralProperty("ResetNo", EdmPrimitiveTypeKind.Int32, false)); var passwordResetUsername = passwordResetType.AddStructuralProperty("Username", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 50, isUnicode: false)); passwordResetType.AddStructuralProperty("TempPassword", EdmPrimitiveTypeKind.String); passwordResetType.AddStructuralProperty("EmailedTo", EdmPrimitiveTypeKind.String); model.AddElement(passwordResetType); var passwordResetLogin = new EdmNavigationPropertyInfo { Name = "Login", Target = loginType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { passwordResetUsername }, PrincipalProperties = loginType.Key() }; passwordResetType.AddUnidirectionalNavigation(passwordResetLogin); var pageViewType = new EdmEntityType("NS1", "PageView"); pageViewType.AddKeys(pageViewType.AddStructuralProperty("PageViewId", EdmPrimitiveTypeKind.Int32, false)); var pageViewUsername = pageViewType.AddStructuralProperty("Username", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 50, isUnicode: false)); pageViewType.AddStructuralProperty("Viewed", EdmPrimitiveTypeKind.DateTimeOffset); pageViewType.AddStructuralProperty("PageUrl", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 500, isUnicode: false)); model.AddElement(pageViewType); var pageViewLogin = new EdmNavigationPropertyInfo { Name = "Login", Target = loginType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { pageViewUsername }, PrincipalProperties = loginType.Key() }; pageViewType.AddUnidirectionalNavigation(pageViewLogin); var productPageViewType = new EdmEntityType("NS1", "ProductPageView", pageViewType); var productPageViewProductId = productPageViewType.AddStructuralProperty("ProductId", EdmPrimitiveTypeKind.Int32, false); model.AddElement(productPageViewType); var productPageViewProduct = new EdmNavigationPropertyInfo { Name = "Product", Target = productType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { productPageViewProductId }, PrincipalProperties = productType.Key() }; productPageViewType.AddUnidirectionalNavigation(productPageViewProduct); var supplierType = new EdmEntityType("NS1", "Supplier"); supplierType.AddKeys(supplierType.AddStructuralProperty("SupplierId", EdmPrimitiveTypeKind.Int32, false)); supplierType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); model.AddElement(supplierType); var supplierProducts = new EdmNavigationPropertyInfo { Name = "Products", Target = productType, TargetMultiplicity = EdmMultiplicity.Many }; var productSuppliers = new EdmNavigationPropertyInfo { Name = "Suppliers", Target = supplierType, TargetMultiplicity = EdmMultiplicity.Many }; supplierType.AddBidirectionalNavigation(supplierProducts, productSuppliers); var supplierLogoType = new EdmEntityType("NS1", "SupplierLogo"); var supplierLogoSupplierId = supplierLogoType.AddStructuralProperty("SupplierId", EdmPrimitiveTypeKind.Int32, false); supplierLogoType.AddKeys(supplierLogoSupplierId); supplierLogoType.AddStructuralProperty("Logo", EdmCoreModel.Instance.GetBinary(isNullable: false, isUnbounded: false, maxLength: 500)); model.AddElement(supplierLogoType); var supplierSupplierLogo = new EdmNavigationPropertyInfo { Name = "Logo", Target = supplierLogoType, TargetMultiplicity = EdmMultiplicity.One, PrincipalProperties = new[] { supplierLogoSupplierId }, DependentProperties = supplierType.Key() }; supplierType.AddUnidirectionalNavigation(supplierSupplierLogo); var supplierInfoType = new EdmEntityType("NS1", "SupplierInfo"); supplierInfoType.AddKeys(supplierInfoType.AddStructuralProperty("SupplierInfoId", EdmPrimitiveTypeKind.Int32, false)); supplierInfoType.AddStructuralProperty("Information", EdmPrimitiveTypeKind.String); model.AddElement(supplierInfoType); var supplierInfoSupplier = new EdmNavigationPropertyInfo { Name = "Supplier", Target = supplierType, TargetMultiplicity = EdmMultiplicity.One, OnDelete = EdmOnDeleteAction.Cascade }; supplierInfoType.AddUnidirectionalNavigation(supplierInfoSupplier); var orderNoteType = new EdmEntityType("NS1", "OrderNote"); orderNoteType.AddKeys(orderNoteType.AddStructuralProperty("NoteId", EdmPrimitiveTypeKind.Int32, false)); orderNoteType.AddStructuralProperty("Note", EdmPrimitiveTypeKind.String); model.AddElement(orderNoteType); var orderNoteOrder = new EdmNavigationPropertyInfo { Name = "Order", Target = orderType, TargetMultiplicity = EdmMultiplicity.One }; var orderOrderNotes = new EdmNavigationPropertyInfo { Name = "Notes", Target = orderNoteType, TargetMultiplicity = EdmMultiplicity.Many, OnDelete = EdmOnDeleteAction.Cascade }; orderNoteType.AddBidirectionalNavigation(orderNoteOrder, orderOrderNotes); var orderQualityCheckType = new EdmEntityType("NS1", "OrderQualityCheck"); var orderQualityCheckOrderId = orderQualityCheckType.AddStructuralProperty("OrderId", EdmPrimitiveTypeKind.Int32, false); orderQualityCheckType.AddKeys(orderQualityCheckOrderId); orderQualityCheckType.AddStructuralProperty("CheckedBy", EdmPrimitiveTypeKind.String); orderQualityCheckType.AddStructuralProperty("CheckedDateTime", EdmPrimitiveTypeKind.DateTimeOffset); model.AddElement(orderQualityCheckType); var orderQualityCheckOrder = new EdmNavigationPropertyInfo { Name = "Order", Target = orderType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { orderQualityCheckOrderId }, PrincipalProperties = orderType.Key() }; orderQualityCheckType.AddUnidirectionalNavigation(orderQualityCheckOrder); var orderLineType = new EdmEntityType("NS1", "OrderLine"); var orderLineOrderId = orderLineType.AddStructuralProperty("OrderId", EdmPrimitiveTypeKind.Int32, false); var orderLineProductId = orderLineType.AddStructuralProperty("ProductId", EdmPrimitiveTypeKind.Int32, false); orderLineType.AddKeys(orderLineOrderId, orderLineProductId); orderLineType.AddStructuralProperty("Quantity", EdmPrimitiveTypeKind.Int32); orderLineType.AddStructuralProperty("ConcurrencyToken", EdmCoreModel.Instance.GetString(false), string.Empty, EdmConcurrencyMode.Fixed); model.AddElement(orderLineType); var orderLineOrder = new EdmNavigationPropertyInfo { Name = "Order", Target = orderType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { orderLineOrderId }, PrincipalProperties = orderType.Key() }; var orderOrderLine = new EdmNavigationPropertyInfo { Name = "OrderLines", Target = orderLineType, TargetMultiplicity = EdmMultiplicity.Many }; orderLineType.AddBidirectionalNavigation(orderLineOrder, orderOrderLine); var orderLineProduct = new EdmNavigationPropertyInfo { Name = "Product", Target = productType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { orderLineProductId }, PrincipalProperties = productType.Key() }; orderLineType.AddUnidirectionalNavigation(orderLineProduct); var backOrderLineType = new EdmEntityType("NS1", "BackOrderLine", orderLineType); backOrderLineType.AddStructuralProperty("ETA", EdmPrimitiveTypeKind.DateTimeOffset); model.AddElement(backOrderLineType); var backOrderLineSupplier = new EdmNavigationPropertyInfo { Name = "Supplier", Target = supplierType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }; var supplierBackOrderLines = new EdmNavigationPropertyInfo { Name = "BackOrderLines", Target = backOrderLineType, TargetMultiplicity = EdmMultiplicity.Many }; backOrderLineType.AddBidirectionalNavigation(backOrderLineSupplier, supplierBackOrderLines); var backOrderLine2Type = new EdmEntityType("NS1", "BackOrderLine2", backOrderLineType); model.AddElement(backOrderLine2Type); var discontinuedProductType = new EdmEntityType("NS1", "DiscontinuedProduct", productType); discontinuedProductType.AddStructuralProperty("Discontinued", EdmPrimitiveTypeKind.DateTimeOffset); var replacementProductId = discontinuedProductType.AddStructuralProperty("ReplacementProductId", EdmCoreModel.Instance.GetInt32(true)); model.AddElement(discontinuedProductType); var discontinuedProductReplacement = new EdmNavigationPropertyInfo { Name = "ReplacedBy", Target = productType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, DependentProperties = new[] { replacementProductId }, PrincipalProperties = productType.Key() }; var productReplaces = new EdmNavigationPropertyInfo { Name = "Replaces", Target = discontinuedProductType, TargetMultiplicity = EdmMultiplicity.Many, }; discontinuedProductType.AddBidirectionalNavigation(discontinuedProductReplacement, productReplaces); var productDetailType = new EdmEntityType("NS1", "ProductDetail"); var productDetailProductId = productDetailType.AddStructuralProperty("ProductId", EdmPrimitiveTypeKind.Int32, false); productDetailType.AddKeys(productDetailProductId); productDetailType.AddStructuralProperty("Details", EdmPrimitiveTypeKind.String); model.AddElement(productDetailType); var productDetailProduct = new EdmNavigationPropertyInfo { Name = "Product", Target = productType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { productDetailProductId }, PrincipalProperties = productType.Key() }; var productProductDetail = new EdmNavigationPropertyInfo { Name = "Detail", Target = productDetailType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }; productDetailType.AddBidirectionalNavigation(productDetailProduct, productProductDetail); var productReviewType = new EdmEntityType("NS1", "ProductReview"); var productReviewProductId = productReviewType.AddStructuralProperty("ProductId", EdmPrimitiveTypeKind.Int32, false); productReviewType.AddKeys(productReviewProductId, productReviewType.AddStructuralProperty("ReviewId", EdmPrimitiveTypeKind.Int32, false)); productReviewType.AddStructuralProperty("Review", EdmPrimitiveTypeKind.String); model.AddElement(productReviewType); var productReviewProduct = new EdmNavigationPropertyInfo { Name = "Product", Target = productType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { productReviewProductId }, PrincipalProperties = productType.Key() }; var productProductReviews = new EdmNavigationPropertyInfo { Name = "Reviews", Target = productReviewType, TargetMultiplicity = EdmMultiplicity.Many }; productReviewType.AddBidirectionalNavigation(productReviewProduct, productProductReviews); var productPhotoType = new EdmEntityType("NS1", "ProductPhoto"); var productPhotoProductId = productPhotoType.AddStructuralProperty("ProductId", EdmPrimitiveTypeKind.Int32, false); productPhotoType.AddKeys(productPhotoProductId, productPhotoType.AddStructuralProperty("PhotoId", EdmPrimitiveTypeKind.Int32, false)); productPhotoType.AddStructuralProperty("Photo", EdmPrimitiveTypeKind.Binary); model.AddElement(productPhotoType); var productProductPhotos = new EdmNavigationPropertyInfo { Name = "Photos", Target = productPhotoType, TargetMultiplicity = EdmMultiplicity.Many }; var productPhotoProduct = new EdmNavigationPropertyInfo { Name = "Product", Target = productType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { productPhotoProductId }, PrincipalProperties = productType.Key() }; productType.AddBidirectionalNavigation(productProductPhotos, productPhotoProduct); var productWebFeatureType = new EdmEntityType("NS1", "ProductWebFeature"); productWebFeatureType.AddKeys(productWebFeatureType.AddStructuralProperty("FeatureId", EdmPrimitiveTypeKind.Int32, false)); var productWebFeatureProductId = productWebFeatureType.AddStructuralProperty("ProductId", EdmCoreModel.Instance.GetInt32(true)); var productWebFeaturePhotoId = productWebFeatureType.AddStructuralProperty("PhotoId", EdmCoreModel.Instance.GetInt32(true)); var productWebFeatureReviewId = productWebFeatureType.AddStructuralProperty("ReviewId", EdmCoreModel.Instance.GetInt32(true)); productWebFeatureType.AddStructuralProperty("Heading", EdmPrimitiveTypeKind.String); model.AddElement(productWebFeatureType); var productReviewWebFeatures = new EdmNavigationPropertyInfo { Name = "Features", Target = productWebFeatureType, TargetMultiplicity = EdmMultiplicity.Many }; var productWebFeatureReview = new EdmNavigationPropertyInfo { Name = "Review", Target = productReviewType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, DependentProperties = new[] { productWebFeatureReviewId, productWebFeatureProductId }, PrincipalProperties = productReviewType.Key() }; productWebFeatureType.AddBidirectionalNavigation(productWebFeatureReview, productReviewWebFeatures); var productPhotoWebFeatures = new EdmNavigationPropertyInfo { Name = "Features", Target = productWebFeatureType, TargetMultiplicity = EdmMultiplicity.Many }; var productWebFeaturePhoto = new EdmNavigationPropertyInfo { Name = "Photo", Target = productPhotoType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, DependentProperties = new[] { productWebFeaturePhotoId, productWebFeatureProductId }, PrincipalProperties = productPhotoType.Key() }; productWebFeatureType.AddBidirectionalNavigation(productWebFeaturePhoto, productPhotoWebFeatures); var computerType = new EdmEntityType("NS1", "Computer"); computerType.AddKeys(computerType.AddStructuralProperty("ComputerId", EdmPrimitiveTypeKind.Int32, false)); computerType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); model.AddElement(computerType); var computerDetailType = new EdmEntityType("NS1", "ComputerDetail"); computerDetailType.AddKeys(computerDetailType.AddStructuralProperty("ComputerDetailId", EdmPrimitiveTypeKind.Int32, false)); computerDetailType.AddStructuralProperty("Model", EdmPrimitiveTypeKind.String); computerDetailType.AddStructuralProperty("Serial", EdmPrimitiveTypeKind.String); computerDetailType.AddStructuralProperty("Specifications", EdmPrimitiveTypeKind.String); computerDetailType.AddStructuralProperty("PurchaseDate", EdmPrimitiveTypeKind.DateTimeOffset); computerDetailType.AddStructuralProperty("Dimensions", dimensionsTypeReference); model.AddElement(computerDetailType); var computerDetailComputer = new EdmNavigationPropertyInfo { Name = "Computer", Target = computerType, TargetMultiplicity = EdmMultiplicity.One }; var computerComputerDetail = new EdmNavigationPropertyInfo { Name = "ComputerDetail", Target = computerDetailType, TargetMultiplicity = EdmMultiplicity.One }; computerType.AddBidirectionalNavigation(computerComputerDetail, computerDetailComputer); var driverType = new EdmEntityType("NS1", "Driver"); driverType.AddKeys(driverType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: 100, isNullable: false, isUnicode: false))); driverType.AddStructuralProperty("BirthDate", EdmPrimitiveTypeKind.DateTimeOffset); model.AddElement(driverType); var licenseType = new EdmEntityType("NS1", "License"); var licenseDriverName = licenseType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: 100, isNullable: false, isUnicode: false)); licenseType.AddKeys(licenseDriverName); licenseType.AddStructuralProperty("LicenseNumber", EdmPrimitiveTypeKind.String); licenseType.AddStructuralProperty("LicenseClass", EdmPrimitiveTypeKind.String); licenseType.AddStructuralProperty("Restrictions", EdmPrimitiveTypeKind.String); licenseType.AddStructuralProperty("ExpirationDate", EdmPrimitiveTypeKind.DateTimeOffset); model.AddElement(licenseType); var driverLicense = new EdmNavigationPropertyInfo { Name = "License", Target = licenseType, TargetMultiplicity = EdmMultiplicity.One, }; var licenseDriver = new EdmNavigationPropertyInfo { Name = "Driver", Target = driverType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { licenseDriverName }, PrincipalProperties = driverType.Key() }; licenseType.AddBidirectionalNavigation(licenseDriver, driverLicense); #endregion model.AddDefaultContainerFixup("NS1"); return model; }
public static IEdmModel AssociationFkEdm() { var model = new EdmModel(); var customerType = new EdmEntityType("NS1", "Customer"); customerType.AddKeys(customerType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); model.AddElement(customerType); var orderType = new EdmEntityType("NS1", "Order"); orderType.AddKeys(orderType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); var orderTypeCustomerId = orderType.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32); model.AddElement(orderType); customerType.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo { Name = "ToOrders", Target = orderType, TargetMultiplicity = EdmMultiplicity.Many, }); orderType.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo { Name = "Customer", Target = customerType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { orderTypeCustomerId }, PrincipalProperties = orderType.Key() }); return model; }
public static IEdmModel AssociationCompositeFkEdm() { var model = new EdmModel(); var customerType = new EdmEntityType("NS1", "Customer"); customerType.AddKeys(customerType.AddStructuralProperty("Id1", EdmPrimitiveTypeKind.Int32)); customerType.AddKeys(customerType.AddStructuralProperty("Id2", EdmPrimitiveTypeKind.Int32)); model.AddElement(customerType); var orderType = new EdmEntityType("NS1", "Order"); orderType.AddKeys(orderType.AddStructuralProperty("Id1", EdmPrimitiveTypeKind.Int32)); var customerId1Property = orderType.AddStructuralProperty("CustomerId1", EdmPrimitiveTypeKind.Int32); var customerId2Property = orderType.AddStructuralProperty("CustomerId2", EdmPrimitiveTypeKind.Int32); model.AddElement(orderType); var navProp = new EdmNavigationPropertyInfo { Name = "ToCustomer", Target = customerType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { customerId1Property, customerId2Property }, PrincipalProperties = customerType.Key() }; orderType.AddUnidirectionalNavigation(navProp); return model; }
static FullPayloadValidateTests() { EntityType = new EdmEntityType("Namespace", "EntityType", null, false, false, false); EntityType.AddKeys(EntityType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); EntityType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(isNullable: true), null, EdmConcurrencyMode.Fixed); DerivedType = new EdmEntityType("Namespace", "DerivedType", EntityType, false, true); var expandedCollectionNavProp = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Target = EntityType, TargetMultiplicity = EdmMultiplicity.Many, Name = "ExpandedCollectionNavProp" }); var expandedNavProp = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Target = EntityType, TargetMultiplicity = EdmMultiplicity.One, Name = "ExpandedNavProp" }); EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Target = EntityType, TargetMultiplicity = EdmMultiplicity.Many, Name = "ContainedCollectionNavProp", ContainsTarget = true }); EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Target = EntityType, TargetMultiplicity = EdmMultiplicity.One, Name = "ContainedNavProp", ContainsTarget = true }); var container = new EdmEntityContainer("Namespace", "Container"); EntitySet = container.AddEntitySet("EntitySet", EntityType); EntitySet.AddNavigationTarget(expandedNavProp, EntitySet); EntitySet.AddNavigationTarget(expandedCollectionNavProp, EntitySet); Model = new EdmModel(); Model.AddElement(EntityType); Model.AddElement(DerivedType); Model.AddElement(container); ModelWithFunction = new EdmModel(); ModelWithFunction.AddElement(EntityType); ModelWithFunction.AddElement(DerivedType); ModelWithFunction.AddElement(container); EdmEntityTypeReference entityTypeReference = new EdmEntityTypeReference(EntityType, false); EdmCollectionTypeReference typeReference = new EdmCollectionTypeReference(new EdmCollectionType(entityTypeReference)); EdmFunction function = new EdmFunction("Namespace", "Function", EdmCoreModel.Instance.GetBoolean(true), true, null, false); function.AddParameter("bindingParameter", typeReference); ModelWithFunction.AddElement(function); EdmAction action = new EdmAction("Namespace", "Action", EdmCoreModel.Instance.GetBoolean(true), true, null); action.AddParameter("bindingParameter", typeReference); ModelWithFunction.AddElement(action); }
public static IEdmModel EntityInheritanceTreeEdm() { var model = new EdmModel(); var rootType = new EdmEntityType("NS1", "Root"); rootType.AddKeys(rootType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); model.AddElement(rootType); var derivedType1_1 = new EdmEntityType("NS1", "DerivedLevel1_1", rootType); derivedType1_1.AddStructuralProperty("PropertyLevel1", EdmPrimitiveTypeKind.Int32); model.AddElement(derivedType1_1); var derivedType1_2 = new EdmEntityType("NS1", "DerivedLevel1_2", rootType); rootType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "RootDerivedLevel1_2", Target = derivedType1_2, TargetMultiplicity = EdmMultiplicity.Many }); model.AddElement(derivedType1_2); var derivedType2_1 = new EdmEntityType("NS1", "DerivedLevel2_1", derivedType1_1); derivedType2_1.AddStructuralProperty("PropertyLevel2", EdmPrimitiveTypeKind.Int32); model.AddElement(derivedType2_1); var derivedType2_2 = new EdmEntityType("NS1", "DerivedLevel2_2", derivedType1_2); derivedType2_2.AddStructuralProperty("PropertyLevel2", EdmPrimitiveTypeKind.Int32); model.AddElement(derivedType2_2); var derivedType2_3 = new EdmEntityType("NS1", "DerivedLevel2_3", derivedType1_2); derivedType2_3.AddStructuralProperty("PropertyLevel2", EdmPrimitiveTypeKind.Int32); model.AddElement(derivedType2_3); return model; }
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 IEdmNavigationSource GetContainedEntitySet(EdmModel model, EdmEntityType type) { EdmEntitySet entitySet = GetEntitySet(model, type); var containedEntity = GetContainedEntityType(model); var navigationPropertyInfo = new EdmNavigationPropertyInfo() { Name = "nav", Target = containedEntity, TargetMultiplicity = EdmMultiplicity.Many, // todo: TargetMultiplicity info seems lost in V4 ContainsTarget = true }; EdmNavigationProperty navigationProperty = EdmNavigationProperty.CreateNavigationProperty(type, navigationPropertyInfo); type.AddUnidirectionalNavigation(navigationPropertyInfo); IEdmNavigationSource containedEntitySet = entitySet.FindNavigationTarget(navigationProperty); return containedEntitySet; }
private static IEdmEntitySetBase GetTargetEntitySet(EdmPathExpression edmPathExpression, out IEdmEntitySet targetEntitySet, bool addParameters = false, bool isBindable = true) { var model = new EdmModel(); var container = new EdmEntityContainer("Fake", "Container"); model.AddElement(container); var edmEntityType = new EdmEntityType("Fake", "EntityType"); var sourceEntitySet = container.AddEntitySet("SourceEntitySet", edmEntityType); var middleEntitySet = container.AddEntitySet("MiddleEntitySet", edmEntityType); targetEntitySet = container.AddEntitySet("TargetEntitySet", edmEntityType); var nav1 = edmEntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Navigation1", Target = edmEntityType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }); var nav2 = edmEntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Navigation2", Target = edmEntityType, TargetMultiplicity = EdmMultiplicity.Many }); sourceEntitySet.AddNavigationTarget(nav1, middleEntitySet); middleEntitySet.AddNavigationTarget(nav2, targetEntitySet); var action = new EdmAction("Fake", "FakeAction", new EdmEntityTypeReference(edmEntityType, false), isBindable, null /*EntitySetPath*/); if (addParameters) { action.AddParameter("p1", new EdmEntityTypeReference(edmEntityType, false)); action.AddParameter("p2", new EdmEntityTypeReference(edmEntityType, false)); } var actionImport = container.AddActionImport("FakeAction", action, edmPathExpression); return actionImport.GetTargetEntitySet(sourceEntitySet, model); }
/// <summary> /// Creates a model, used model information at http://schema.org/Person as inspiration /// </summary> /// <returns></returns> public static IEdmModel BuildModel(string modelNamespace) { var edmModel = new EdmModel(); var container = new EdmEntityContainer(modelNamespace, "Container"); edmModel.AddElement(container); // Create types var addressType = new EdmComplexType(modelNamespace, "PostalAddress"); addressType.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String); addressType.AddStructuralProperty("City", EdmPrimitiveTypeKind.String); addressType.AddStructuralProperty("State", EdmPrimitiveTypeKind.String); addressType.AddStructuralProperty("ZipCode", EdmPrimitiveTypeKind.String); var addressRefType = new EdmComplexTypeReference(addressType, true); var placeType = new EdmEntityType(modelNamespace, "Place"); var placeTypeKeyProp = placeType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); placeType.AddKeys(placeTypeKeyProp); placeType.AddStructuralProperty("MapUri", EdmPrimitiveTypeKind.String); placeType.AddStructuralProperty("TelephoneNumber", EdmPrimitiveTypeKind.String); placeType.AddStructuralProperty("Address", addressRefType); var personType = new EdmEntityType(modelNamespace, "Person"); var personTypeKeyProp = personType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); personType.AddKeys(personTypeKeyProp); personType.AddStructuralProperty("FirstName", EdmPrimitiveTypeKind.String); personType.AddStructuralProperty("LastName", EdmPrimitiveTypeKind.String); personType.AddStructuralProperty("Address", addressRefType); var organizationType = new EdmEntityType(modelNamespace, "Organization"); var organizationTypeKeyProp = organizationType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); organizationType.AddKeys(organizationTypeKeyProp); organizationType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); organizationType.AddStructuralProperty("Address", addressRefType); var corporationType = new EdmEntityType(modelNamespace, "Corporation", organizationType); corporationType.AddStructuralProperty("TickerSymbol", EdmPrimitiveTypeKind.String); var localBusinessType = new EdmEntityType(modelNamespace, "LocalBusiness", organizationType); // Create associations personType.AddBidirectionalNavigation( new EdmNavigationPropertyInfo() {Name = "Employers", Target = organizationType, TargetMultiplicity = EdmMultiplicity.Many}, new EdmNavigationPropertyInfo() {Name = "Employees", Target = personType, TargetMultiplicity = EdmMultiplicity.Many}); personType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "CurrentPosition", Target = placeType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }); personType.AddBidirectionalNavigation( new EdmNavigationPropertyInfo() { Name = "Children", Target = personType, TargetMultiplicity = EdmMultiplicity.Many }, new EdmNavigationPropertyInfo() { Name = "Parent", Target = personType, TargetMultiplicity = EdmMultiplicity.One }); localBusinessType.AddBidirectionalNavigation( new EdmNavigationPropertyInfo() { Name = "LocalBusinessBranches", Target = organizationType, TargetMultiplicity = EdmMultiplicity.Many }, new EdmNavigationPropertyInfo() { Name = "MainOrganization", Target = localBusinessType, TargetMultiplicity = EdmMultiplicity.One }); edmModel.AddElement(addressType); edmModel.AddElement(personType); edmModel.AddElement(organizationType); edmModel.AddElement(corporationType); edmModel.AddElement(localBusinessType); edmModel.AddElement(placeType); container.AddEntitySet("People", personType); container.AddEntitySet("Organizations", organizationType); container.AddEntitySet("Places", organizationType); return edmModel; }
private IEdmModel GetModel() { if (_model != null) { return _model; } var model = new EdmModel(); // EntityContainer: Service var container = new EdmEntityContainer("ns", "Service"); model.AddElement(container); // EntityType: Address var address = new EdmEntityType("ns", "Address"); var addressId = address.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); address.AddKeys(addressId); model.AddElement(address); // EntitySet: Addresses var addresses = container.AddEntitySet("Addresses", address); // EntityType: PaymentInstrument var paymentInstrument = new EdmEntityType("ns", "PaymentInstrument"); var paymentInstrumentId = paymentInstrument.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); paymentInstrument.AddKeys(paymentInstrumentId); var billingAddresses = paymentInstrument.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "BillingAddresses", Target = address, TargetMultiplicity = EdmMultiplicity.Many }); paymentInstrument.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ContainedBillingAddresses", Target = address, TargetMultiplicity = EdmMultiplicity.Many, ContainsTarget = true }); model.AddElement(paymentInstrument); // EntityType: Account var account = new EdmEntityType("ns", "Account"); var accountId = account.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); account.AddKeys(accountId); var myPaymentInstruments = account.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MyPaymentInstruments", Target = paymentInstrument, TargetMultiplicity = EdmMultiplicity.Many, ContainsTarget = true }); model.AddElement(account); // EntitySet: Accounts var accounts = container.AddEntitySet("Accounts", account); var paymentInstruments = accounts.FindNavigationTarget(myPaymentInstruments) as EdmNavigationSource; Assert.NotNull(paymentInstruments); paymentInstruments.AddNavigationTarget(billingAddresses, addresses); // EntityType: Person var person = new EdmEntityType("ns", "Person"); var personId = person.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); person.AddKeys(personId); var myAccounts = person.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MyAccounts", Target = account, TargetMultiplicity = EdmMultiplicity.Many }); var myPermanentAccount = person.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MyPermanentAccount", Target = account, TargetMultiplicity = EdmMultiplicity.One }); var myLatestAccount = person.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MyLatestAccount", Target = account, TargetMultiplicity = EdmMultiplicity.One }); person.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MyAddresses", Target = address, TargetMultiplicity = EdmMultiplicity.Many, ContainsTarget = true }); model.AddElement(person); // EntityType: Benefit var benefit = new EdmEntityType("ns", "Benefit"); var benefitId = benefit.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); benefit.AddKeys(benefitId); model.AddElement(benefit); // EntityType: SpecialPerson var specialPerson = new EdmEntityType("ns", "SpecialPerson", person); specialPerson.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Benefits", Target = benefit, TargetMultiplicity = EdmMultiplicity.Many, ContainsTarget = true }); model.AddElement(specialPerson); // EntityType: VIP var vip = new EdmEntityType("ns", "VIP", specialPerson); vip.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MyBenefits", Target = benefit, TargetMultiplicity = EdmMultiplicity.Many, ContainsTarget = true }); model.AddElement(vip); // EntitySet: People var people = container.AddEntitySet("People", person); people.AddNavigationTarget(myAccounts, accounts); people.AddNavigationTarget(myLatestAccount, accounts); // EntityType: Club var club = new EdmEntityType("ns", "Club"); var clubId = club.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); club.AddKeys(clubId); var members = club.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Members", Target = person, TargetMultiplicity = EdmMultiplicity.Many, ContainsTarget = true }); // EntityType: SeniorClub var seniorClub = new EdmEntityType("ns", "SeniorClub", club); model.AddElement(seniorClub); // EntitySet: Clubs var clubs = container.AddEntitySet("Clubs", club); var membersInClub = clubs.FindNavigationTarget(members) as EdmNavigationSource; membersInClub.AddNavigationTarget(myAccounts, accounts); // Singleton: PermanentAccount var permanentAccount = container.AddSingleton("PermanentAccount", account); people.AddNavigationTarget(myPermanentAccount, permanentAccount); _model = model; return _model; }