当前位置: 首页>>代码示例>>C#>>正文


C# EdmEntityType.AddBidirectionalNavigation方法代码示例

本文整理汇总了C#中Microsoft.OData.Edm.Library.EdmEntityType.AddBidirectionalNavigation方法的典型用法代码示例。如果您正苦于以下问题:C# EdmEntityType.AddBidirectionalNavigation方法的具体用法?C# EdmEntityType.AddBidirectionalNavigation怎么用?C# EdmEntityType.AddBidirectionalNavigation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.OData.Edm.Library.EdmEntityType的用法示例。


在下文中一共展示了EdmEntityType.AddBidirectionalNavigation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Initialize

        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);
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:50,代码来源:SelectedPropertiesNodeTests.cs

示例2: ModelWithAllConceptsEdm

        public static IEdmModel ModelWithAllConceptsEdm()
        {
            var stringType = EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String);

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

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

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

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

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

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

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

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

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

            return model;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:52,代码来源:ModelBuilder.cs

示例3: AssociationIndependentEdm

        public static IEdmModel AssociationIndependentEdm()
        {
            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));
            model.AddElement(orderType);

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

            return model;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:17,代码来源:ModelBuilder.cs

示例4: MultipleNamespacesEdm

        public static IEdmModel MultipleNamespacesEdm()
        {
            var model = new EdmModel();
            var personType = new EdmEntityType("NS1", "Person");
            personType.AddKeys(personType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
            model.AddElement(personType);

            var complexType1 = new EdmComplexType("NS3", "ComplexLevel1");
            model.AddElement(complexType1);
            var complexType2 = new EdmComplexType("NS2", "ComplexLevel2");
            model.AddElement(complexType2);
            var complexType3 = new EdmComplexType("NS2", "ComplexLevel3");
            model.AddElement(complexType3);

            complexType3.AddStructuralProperty("IntProperty", EdmPrimitiveTypeKind.Int32);
            complexType2.AddStructuralProperty("ComplexProperty", new EdmComplexTypeReference(complexType3, false));
            complexType1.AddStructuralProperty("ComplexProperty", new EdmComplexTypeReference(complexType2, false));
            personType.AddStructuralProperty("ComplexProperty", new EdmComplexTypeReference(complexType1, false));

            var customerType = new EdmEntityType("NS3", "Customer", personType);
            model.AddElement(customerType);

            var orderType = new EdmEntityType("NS2", "Order");
            orderType.AddKeys(orderType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
            model.AddElement(orderType);

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

            return model;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:33,代码来源:ModelBuilder.cs

示例5: BuildModel

        /// <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;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:71,代码来源:Utils.cs

示例6: TwoWayNavigationPropertyMultipleMappingInSingletonTest

        public void TwoWayNavigationPropertyMultipleMappingInSingletonTest()
        {
            var model = new EdmModel();
            var t3 = new EdmEntityType("Bunk", "T3");
            var f31 = t3.AddStructuralProperty("F31", EdmCoreModel.Instance.GetString(false));
            t3.AddKeys(f31);
            model.AddElement(t3);

            var t1 = new EdmEntityType("Bunk", "T1");
            var f11 = t1.AddStructuralProperty("F11", EdmCoreModel.Instance.GetString(false));
            t1.AddKeys(f11);
            var p101 = t1.AddBidirectionalNavigation
                                    (
                                        new EdmNavigationPropertyInfo() { Name = "P101", Target = t3, TargetMultiplicity = EdmMultiplicity.One },
                                        new EdmNavigationPropertyInfo() { Name = "P301", TargetMultiplicity = EdmMultiplicity.One }
                                    );
            model.AddElement(t1);

            var c1 = new EdmEntityContainer("Bunk", "Gunk");
            var E1a = c1.AddEntitySet("E1a", t1);
            var E1b = c1.AddSingleton("E1b", t1);
            var E3 = c1.AddSingleton("E3", t3);
            E1a.AddNavigationTarget(p101, E3);
            E1b.AddNavigationTarget(p101, E3);
            E3.AddNavigationTarget(p101.Partner, E1a);
            model.AddElement(c1);

            var expectedErrors = new EdmLibTestErrors()
            {
                { "(Microsoft.OData.Edm.Library.EdmSingleton)", EdmErrorCode.NavigationMappingMustBeBidirectional },
            };
            IEnumerable<EdmError> edmErrors;
            model.Validate(out edmErrors);
            this.CompareErrors(edmErrors, expectedErrors);
        }
开发者ID:spawnadv,项目名称:msgraphodata.net,代码行数:35,代码来源:SemanticValidationTests.cs

示例7: ConstructibleModelODataTestModelDefaultModel


//.........这里部分代码省略.........
            EdmStructuralProperty carVin = car.AddStructuralProperty("VIN", EdmCoreModel.Instance.GetInt32(false));
            car.AddKeys(carVin);
            EdmStructuralProperty carDescription = car.AddStructuralProperty("Description", EdmCoreModel.Instance.GetString(false, 100, null, true));
            EdmStructuralProperty carPhoto = car.AddStructuralProperty("Photo", EdmCoreModel.Instance.GetStream(false));
            EdmStructuralProperty carVideo = car.AddStructuralProperty("Video", EdmCoreModel.Instance.GetStream(false));
            model.AddElement(car);

            EdmEntityType person = new EdmEntityType("DefaultNamespace", "Person");
            EdmStructuralProperty personId = person.AddStructuralProperty("PersonId", EdmCoreModel.Instance.GetInt32(false));
            person.AddKeys(personId);
            EdmStructuralProperty personName = person.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false));
            model.AddElement(person);

            EdmEntityType employee = new EdmEntityType("DefaultNamespace", "Employee", person);
            EdmStructuralProperty employeeManagerId = employee.AddStructuralProperty("ManagersPersonId", EdmCoreModel.Instance.GetInt32(false));
            EdmStructuralProperty employeeSalary = employee.AddStructuralProperty("Salary", EdmCoreModel.Instance.GetInt32(false));
            EdmStructuralProperty employeeTitle = employee.AddStructuralProperty("Title", EdmCoreModel.Instance.GetString(false));
            model.AddElement(employee);

            EdmEntityType specialEmployee = new EdmEntityType("DefaultNamespace", "SpecialEmployee", employee);
            EdmStructuralProperty specialEmployeeCarsVIN = specialEmployee.AddStructuralProperty("CarsVIN", EdmCoreModel.Instance.GetInt32(false));
            EdmStructuralProperty specialEmployeeBonus = specialEmployee.AddStructuralProperty("Bonus", EdmCoreModel.Instance.GetInt32(false));
            EdmStructuralProperty specialEmployeeIsFullyVested = specialEmployee.AddStructuralProperty("IsFullyVested", EdmCoreModel.Instance.GetBoolean(false));
            model.AddElement(specialEmployee);

            EdmEntityType personMetadata = new EdmEntityType("DefaultNamespace", "PersonMetadata");
            EdmStructuralProperty personMetadataId = personMetadata.AddStructuralProperty("PersonMetadataId", EdmCoreModel.Instance.GetInt32(false));
            personMetadata.AddKeys(personMetadataId);
            EdmStructuralProperty personMetadataPersonId = personMetadata.AddStructuralProperty("PersonId", EdmCoreModel.Instance.GetInt32(false));
            EdmStructuralProperty personMetadataPropertyName = personMetadata.AddStructuralProperty("PropertyName", EdmCoreModel.Instance.GetString(false));
            EdmStructuralProperty personMetadataPropertyValue = personMetadata.AddStructuralProperty("PropertyValue", EdmCoreModel.Instance.GetString(false));
            model.AddElement(personMetadata);

            EdmNavigationProperty customerToOrders = customer.AddBidirectionalNavigation(
                new EdmNavigationPropertyInfo() { Name = "Orders", Target = order, TargetMultiplicity = EdmMultiplicity.Many },
                new EdmNavigationPropertyInfo() { Name = "Customer", TargetMultiplicity = EdmMultiplicity.ZeroOrOne, DependentProperties = new[] { orderCustomerId }, PrincipalProperties = customer.Key() });

            EdmNavigationProperty customerToLogins = customer.AddBidirectionalNavigation(
                new EdmNavigationPropertyInfo() { Name = "Logins", Target = login, TargetMultiplicity = EdmMultiplicity.Many },
                new EdmNavigationPropertyInfo() { Name = "Customer", TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new [] { loginCustomerId }, PrincipalProperties = customer.Key()});

            EdmNavigationProperty customerToHusband = customer.AddBidirectionalNavigation(
                new EdmNavigationPropertyInfo() { Name = "Husband", Target = customer, TargetMultiplicity = EdmMultiplicity.ZeroOrOne },
                new EdmNavigationPropertyInfo() { Name = "Wife", TargetMultiplicity = EdmMultiplicity.ZeroOrOne });

            EdmNavigationProperty customerToInfo = customer.AddBidirectionalNavigation(
                new EdmNavigationPropertyInfo() { Name = "Info", Target = customerInfo, TargetMultiplicity = EdmMultiplicity.ZeroOrOne },
                new EdmNavigationPropertyInfo() { Name = "Customer", TargetMultiplicity = EdmMultiplicity.One });

            EdmNavigationProperty customerToComplaint = customer.AddBidirectionalNavigation(
                new EdmNavigationPropertyInfo() { Name = "Complaints", Target = complaint, TargetMultiplicity = EdmMultiplicity.Many },
                new EdmNavigationPropertyInfo() { Name = "Customer", TargetMultiplicity = EdmMultiplicity.ZeroOrOne, DependentProperties = new[] { complaintCustomerId }, PrincipalProperties = customer.Key() });

            EdmNavigationProperty barcodeToProduct = barcode.AddBidirectionalNavigation(
                new EdmNavigationPropertyInfo() { Name = "Product", Target = product, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { barcodeProductId }, PrincipalProperties = product.Key() },
                new EdmNavigationPropertyInfo() { Name = "Barcodes", TargetMultiplicity = EdmMultiplicity.Many });

            EdmNavigationProperty barcodeToExpectedIncorrectScans = barcode.AddBidirectionalNavigation(
                new EdmNavigationPropertyInfo() { Name = "BadScans", Target = incorrectScan, TargetMultiplicity = EdmMultiplicity.Many },
                new EdmNavigationPropertyInfo() { Name = "ExpectedBarcode", TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { incorrectScanExpectedCode }, PrincipalProperties = barcode.Key() });

            EdmNavigationProperty barcodeToActualIncorrectScans = barcode.AddBidirectionalNavigation(
                new EdmNavigationPropertyInfo() { Name = "GoodScans", Target = incorrectScan, TargetMultiplicity = EdmMultiplicity.Many },
                new EdmNavigationPropertyInfo() { Name = "ActualBarcode", TargetMultiplicity = EdmMultiplicity.ZeroOrOne, DependentProperties = new[] { incorrectScanActualCode }, PrincipalProperties = barcode.Key()});

            EdmNavigationProperty barcodeToBarcodeDetail = barcode.AddBidirectionalNavigation(
开发者ID:AlineGuan,项目名称:odata.net,代码行数:67,代码来源:ConstructibleModelTestsUsingConverter.cs

示例8: ModelWithInvalidDependentProperties

        public static IEdmModel ModelWithInvalidDependentProperties()
        {
            EdmModel model = new EdmModel();

            var entity1 = new EdmEntityType("Foo", "Bar");
            var id1 = new EdmStructuralProperty(entity1, "Id", EdmCoreModel.Instance.GetInt16(false), null, EdmConcurrencyMode.None);
            entity1.AddKeys(id1);

            var entity2 = new EdmEntityType("Foo", "Baz");
            var id2 = new EdmStructuralProperty(entity2, "Id", EdmCoreModel.Instance.GetInt16(false), null, EdmConcurrencyMode.None);
            entity2.AddKeys(id2);

            EdmNavigationProperty entity1Navigation = entity1.AddBidirectionalNavigation(
                new EdmNavigationPropertyInfo() { Name = "ToBaz", Target = entity2, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { id2 }, PrincipalProperties = entity2.Key() },
                new EdmNavigationPropertyInfo() { Name = "ToBar", TargetMultiplicity = EdmMultiplicity.Many }); 

            model.AddElement(entity1);

            return model;
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:20,代码来源:ValidationTestModelBuilder.cs

示例9: InitializeEdmModel

        private void InitializeEdmModel()
        {
            this.edmModel = new EdmModel();

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

            EdmComplexType addressType = new EdmComplexType("TestModel", "Address");
            addressType.AddStructuralProperty("Street", EdmCoreModel.Instance.GetString(/*isNullable*/false));
            addressType.AddStructuralProperty("Zip", EdmCoreModel.Instance.GetString(/*isNullable*/false));

            this.cityType = new EdmEntityType("TestModel", "City");
            EdmStructuralProperty cityIdProperty = cityType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(/*isNullable*/false));
            cityType.AddKeys(cityIdProperty);
            cityType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(/*isNullable*/false));
            cityType.AddStructuralProperty("Size", EdmCoreModel.Instance.GetInt32(/*isNullable*/false));
            cityType.AddStructuralProperty("Restaurants", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetString(/*isNullable*/false)));
            cityType.AddStructuralProperty("Address", new EdmComplexTypeReference(addressType, true));
            this.edmModel.AddElement(cityType);

            this.capitolCityType = new EdmEntityType("TestModel", "CapitolCity", cityType);
            capitolCityType.AddStructuralProperty("CapitolType", EdmCoreModel.Instance.GetString( /*isNullable*/false));
            this.edmModel.AddElement(capitolCityType);

            EdmEntityType districtType = new EdmEntityType("TestModel", "District");
            EdmStructuralProperty districtIdProperty = districtType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(/*isNullable*/false));
            districtType.AddKeys(districtIdProperty);
            districtType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(/*isNullable*/false));
            districtType.AddStructuralProperty("Zip", EdmCoreModel.Instance.GetInt32(/*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 });

            cityType.NavigationProperties().Single(np => np.Name == "Districts");
            capitolCityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "CapitolDistrict", Target = districtType, TargetMultiplicity = EdmMultiplicity.One });
            capitolCityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "OutlyingDistricts", Target = districtType, TargetMultiplicity = EdmMultiplicity.Many });

            this.citySet = defaultContainer.AddEntitySet("Cities", cityType);
            defaultContainer.AddEntitySet("Districts", districtType);

            this.singletonCity = defaultContainer.AddSingleton("SingletonCity", cityType);
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:44,代码来源:ODataContextUriBuilderTests.cs

示例10: DollarMetadata_Works_WithMultipleReferentialConstraints_ForUntypeModel

        public void DollarMetadata_Works_WithMultipleReferentialConstraints_ForUntypeModel()
        {
            // Arrange
            EdmModel model = new EdmModel();

            EdmEntityType customer = new EdmEntityType("DefaultNamespace", "Customer");
            customer.AddKeys(customer.AddStructuralProperty("CustomerId", EdmCoreModel.Instance.GetInt32(isNullable: false)));
            customer.AddStructuralProperty("Name",
                EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: 100, isUnicode: null, isNullable: false));
            model.AddElement(customer);

            EdmEntityType order = new EdmEntityType("DefaultNamespace", "Order");
            order.AddKeys(order.AddStructuralProperty("OrderId", EdmCoreModel.Instance.GetInt32(false)));
            EdmStructuralProperty orderCustomerId = order.AddStructuralProperty("CustomerForeignKey", EdmCoreModel.Instance.GetInt32(true));
            model.AddElement(order);

            customer.AddBidirectionalNavigation(
                new EdmNavigationPropertyInfo
                {
                    Name = "Orders", Target = order, TargetMultiplicity = EdmMultiplicity.Many
                },
                new EdmNavigationPropertyInfo
                {
                    Name = "Customer", TargetMultiplicity = EdmMultiplicity.ZeroOrOne,
                    DependentProperties = new[] { orderCustomerId },
                    PrincipalProperties = customer.Key()
                });

            const string expect =
                "        <Property Name=\"CustomerForeignKey\" Type=\"Edm.Int32\" />\r\n" +
                "        <NavigationProperty Name=\"Customer\" Type=\"DefaultNamespace.Customer\" Partner=\"Orders\">\r\n" +
                "          <ReferentialConstraint Property=\"CustomerForeignKey\" ReferencedProperty=\"CustomerId\" />\r\n" +
                "        </NavigationProperty>";

            HttpConfiguration config = new[] { typeof(MetadataController) }.GetHttpConfiguration();
            HttpServer server = new HttpServer(config);
            config.MapODataServiceRoute("odata", "odata", model);

            HttpClient client = new HttpClient(server);

            // Act
            HttpResponseMessage response = client.GetAsync("http://localhost/odata/$metadata").Result;

            // Assert
            Assert.True(response.IsSuccessStatusCode);
            Assert.Equal("application/xml", response.Content.Headers.ContentType.MediaType);
            Assert.Contains(expect, response.Content.ReadAsStringAsync().Result);
        }
开发者ID:shailendra9,项目名称:WebApi,代码行数:48,代码来源:MetadataControllerTest.cs

示例11: CreateODataServiceModel


//.........这里部分代码省略.........
            EdmSingleton company = new EdmSingleton(defaultContainer, "Company", companyType);
            defaultContainer.AddElement(company);

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

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

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

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

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

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

            var companyDepartmentsNavigation = companyType.AddBidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "Departments",
                Target = departmentType,
                TargetMultiplicity = EdmMultiplicity.Many
            },
            new EdmNavigationPropertyInfo()
            {
                Name = "Company",
开发者ID:VikingsFan,项目名称:odata.net,代码行数:67,代码来源:DefaultInMemoryModel.cs

示例12: NavigationPropertyWithAnnotationModel

        public static EdmModel NavigationPropertyWithAnnotationModel()
        {
            EdmModel model = new EdmModel();

            EdmEntityType person = new EdmEntityType("DefaultNamespace", "Person");
            EdmStructuralProperty personId = person.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false));
            person.AddKeys(personId);
            model.AddElement(person);

            EdmNavigationProperty friend = person.AddBidirectionalNavigation(
                new EdmNavigationPropertyInfo() { Name = "Friends", Target = person, TargetMultiplicity = EdmMultiplicity.One },
                new EdmNavigationPropertyInfo() { Name = "Self", TargetMultiplicity = EdmMultiplicity.One });
            IEdmNavigationProperty self = friend.Partner;

            XElement annotationElement =
                new XElement("{http://foo}Annotation", "1");
            var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString());
            annotation.SetIsSerializedAsElement(model, true);
            model.SetAnnotationValue(friend, "http://foo", "Annotation", annotation);

            return model;
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:22,代码来源:XElementAnnotationModelBuilder.cs

示例13: ModelWithAssociationEndAsInaccessibleEntityType

        public static IEdmModel ModelWithAssociationEndAsInaccessibleEntityType()
        {
            EdmModel model = new EdmModel();

            var entity1 = new EdmEntityType("Foo", "Bar");
            entity1.AddKeys(entity1.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt16(false), null, EdmConcurrencyMode.None));


            var entity2 = new EdmEntityType("Foo", "Baz");
            entity2.AddKeys(entity2.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt16(false), null, EdmConcurrencyMode.None));

            EdmNavigationProperty entity1Navigation = entity1.AddBidirectionalNavigation(
                new EdmNavigationPropertyInfo() { Name = "ToBaz", Target = entity2, TargetMultiplicity = EdmMultiplicity.ZeroOrOne },
                new EdmNavigationPropertyInfo() { Name = "ToBar", TargetMultiplicity = EdmMultiplicity.ZeroOrOne });

            model.AddElement(entity1);

            return model;
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:19,代码来源:ValidationTestModelBuilder.cs

示例14: AssociationOnDeleteModelEdm

        public static IEdmModel AssociationOnDeleteModelEdm()
        {
            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));
            model.AddElement(orderType);

            var customerIdProperty = orderType.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32);
            var navProp1 = new EdmNavigationPropertyInfo { Name = "ToOrders", Target = orderType, TargetMultiplicity = EdmMultiplicity.Many, OnDelete = EdmOnDeleteAction.Cascade };
            var navProp2 = new EdmNavigationPropertyInfo { Name = "ToCustomer", Target = customerType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { customerIdProperty }, PrincipalProperties = customerType.Key(), OnDelete = EdmOnDeleteAction.None };
            customerType.AddBidirectionalNavigation(navProp1, navProp2);

            return model;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:18,代码来源:ModelBuilder.cs

示例15: GetEdmModel


//.........这里部分代码省略.........
                {
                    Name = "MyContainedDog",
                    TargetMultiplicity = EdmMultiplicity.ZeroOrOne,
                    Target = FullyQualifiedNamespaceDog,
                    ContainsTarget = true
                });
            FullyQualifiedNamespacePerson.AddUnidirectionalNavigation(
                new EdmNavigationPropertyInfo
                {
                    Name = "MyContainedChimeras",
                    TargetMultiplicity = EdmMultiplicity.Many,
                    Target = FullyQualifiedNamespaceChimera,
                    ContainsTarget = true
                });

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

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

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

            model.AddElement(FullyQualifiedNamespacePerson);

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

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

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

            model.AddElement(FullyQualifiedNamespaceOpenEmployee);

            var FullyQualifiedNamespaceDog_ID = FullyQualifiedNamespaceDog.AddStructuralProperty("ID", EdmCoreModel.Instance.GetInt32(false));
            FullyQualifiedNamespaceDog.AddStructuralProperty("Color", EdmCoreModel.Instance.GetString(true));
            FullyQualifiedNamespaceDog.AddStructuralProperty("Nicknames", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(true))));
            FullyQualifiedNamespaceDog.AddStructuralProperty("Breed", EdmCoreModel.Instance.GetString(true));
            FullyQualifiedNamespaceDog.AddStructuralProperty("NamedStream", EdmCoreModel.Instance.GetStream(true));
            FullyQualifiedNamespaceDog.AddKeys(new IEdmStructuralProperty[] { FullyQualifiedNamespaceDog_ID, });
            var FullyQualifiedNamespaceDog_MyPeople = FullyQualifiedNamespaceDog.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MyPeople", TargetMultiplicity = EdmMultiplicity.Many, Target = FullyQualifiedNamespacePerson });
            var FullyQualifiedNamespaceDog_FastestOwner = FullyQualifiedNamespaceDog.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "FastestOwner", TargetMultiplicity = EdmMultiplicity.ZeroOrOne, Target = FullyQualifiedNamespacePerson });
            var FullyQualifiedNamespaceDog_LionWhoAteMe = FullyQualifiedNamespaceDog.AddBidirectionalNavigation(
开发者ID:rossjempson,项目名称:odata.net,代码行数:67,代码来源:HardCodedTestModel.cs


注:本文中的Microsoft.OData.Edm.Library.EdmEntityType.AddBidirectionalNavigation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。