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


C# EdmModel.AddElements方法代码示例

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


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

示例1: MultipleSchemasWithDifferentNamespacesEdm

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

示例2: Invalid_CastTests

        public void Invalid_CastTests(string path)
        {
            // Arrange
            EdmModel model = new EdmModel();
            EdmEntityContainer container = new EdmEntityContainer("NS", "Container");
            var vehicle = new EdmEntityType("NS", "Vehicle");
            var car = new EdmEntityType("NS", "Car", vehicle);
            var motorcycle = new EdmEntityType("NS", "Motorcycle", vehicle);
            model.AddElements(new IEdmSchemaElement[] { vehicle, car, motorcycle, container });

            container.AddEntitySet("Vehicles", vehicle);
            container.AddEntitySet("Cars", car);
            container.AddEntitySet("Motorcycles", motorcycle);

            // Act
            var exception = Assert.Throws<ODataException>(() => _parser.Parse(model, path));
            Assert.Contains("Invalid cast encountered.", exception.Message);
        }
开发者ID:nicholaspei,项目名称:aspnetwebstack,代码行数:18,代码来源:DefaultODataPathHandlerTest.cs

示例3: CastTests

        public void CastTests(string path, string expectedEdmType)
        {
            // Arrange
            EdmModel model = new EdmModel();
            EdmEntityContainer container = new EdmEntityContainer("NS", "Container");
            var vehicle = new EdmEntityType("NS", "Vehicle");
            var car = new EdmEntityType("NS", "Car", vehicle);
            var motorcycle = new EdmEntityType("NS", "Motorcycle", vehicle);
            model.AddElements(new IEdmSchemaElement[] { vehicle, car, motorcycle, container });

            container.AddEntitySet("Vehicles", vehicle);
            container.AddEntitySet("Cars", car);
            container.AddEntitySet("Motorcycles", motorcycle);
            container.AddSingleton("Contoso", vehicle);

            // Act
            ODataPath odataPath = _parser.Parse(model, path);

            // Assert
            Assert.NotNull(odataPath);
            Assert.Equal(expectedEdmType, odataPath.EdmType.ToTraceString());
        }
开发者ID:nicholaspei,项目名称:aspnetwebstack,代码行数:22,代码来源:DefaultODataPathHandlerTest.cs

示例4: ActionOverloadResoultionTests

        [InlineData("Cars/NS.Vehicle/NS.WashMultiple", "WashMultiple", "Collection([NS.Vehicle Nullable=False])")] // downcast
        public void ActionOverloadResoultionTests(string path, string actionName, string expectedEntityBound)
        {
            // Arrange
            EdmModel model = new EdmModel();
            EdmEntityContainer container = new EdmEntityContainer("NS", "Container");
            var vehicle = new EdmEntityType("NS", "Vehicle");
            var car = new EdmEntityType("NS", "Car", vehicle);
            var motorcycle = new EdmEntityType("NS", "Motorcycle", vehicle);
            model.AddElements(new IEdmSchemaElement[] { vehicle, car, motorcycle, container });

            var washVehicle = AddBindableAction(model, "Wash", vehicle, isCollection: false);
            var washCar = AddBindableAction(model, "Wash", car, isCollection: false);
            var washVehicles = AddBindableAction(model, "WashMultiple", vehicle, isCollection: true);
            var washCars = AddBindableAction(model, "WashMultiple", car, isCollection: true);

            container.AddEntitySet("Vehicles", vehicle);
            container.AddEntitySet("Cars", car);
            container.AddEntitySet("Motorcycles", motorcycle);
            container.AddSingleton("Contoso", vehicle);

            // Act
            ODataPath odataPath = _parser.Parse(model, path);

            // Assert
            Assert.NotNull(odataPath);
            BoundActionPathSegment actionSegment = Assert.IsType<BoundActionPathSegment>(odataPath.Segments.Last());
            Assert.Equal("NS." + actionName, actionSegment.ActionName);
            Assert.Equal(expectedEntityBound, actionSegment.Action.Parameters.First().Type.Definition.ToTraceString());
        }
开发者ID:nicholaspei,项目名称:aspnetwebstack,代码行数:30,代码来源:DefaultODataPathHandlerTest.cs

示例5: PropertyFacetsCollectionEdm

        public static IEdmModel PropertyFacetsCollectionEdm()
        {
            var typeReferences = new IEdmTypeReference[]
            {
                EdmCoreModel.Instance.GetDecimal(precision:2, scale:2, isNullable:false),
                EdmCoreModel.Instance.GetString(isUnbounded:false, maxLength:100, isUnicode:false, isNullable:false),
                EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetString(isUnbounded:false, maxLength:100, isUnicode:false, isNullable:false)),
            };

            var model = new EdmModel();
            var entityType = new EdmEntityType("Namespace", "EntityType1");
            var complexType = new EdmComplexType("Namespace", "ComplexType1");
            entityType.AddKeys(entityType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, false));

            int counter = 0;
            foreach (var edmTypeReference in typeReferences)
            {
                entityType.AddStructuralProperty("prop_" + counter, edmTypeReference);
                complexType.AddStructuralProperty("property" + counter, edmTypeReference);
                counter++;
            }

            model.AddElements(new IEdmSchemaElement[] { entityType, complexType });
            return model;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:25,代码来源:ModelBuilder.cs

示例6: Invalid_CastTests

        public void Invalid_CastTests(string path, string expectedError)
        {
            // Arrange
            EdmModel model = new EdmModel();
            EdmEntityContainer container = new EdmEntityContainer("NS", "Container");
            var vehicle = new EdmEntityType("NS", "Vehicle");
            vehicle.AddKeys(vehicle.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
            var car = new EdmEntityType("NS", "Car", vehicle);
            var motorcycle = new EdmEntityType("NS", "Motorcycle", vehicle);
            model.AddElements(new IEdmSchemaElement[] { vehicle, car, motorcycle, container });

            container.AddEntitySet("Vehicles", vehicle);
            container.AddEntitySet("Cars", car);
            container.AddEntitySet("Motorcycles", motorcycle);

            // Act & Assert
            Assert.Throws<ODataException>(
                () => _parser.Parse(model, _serviceRoot, path),
                expectedError);
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:20,代码来源:DefaultODataPathHandlerTest.cs

示例7: BuildModelFromTypes

 private static IEdmModel BuildModelFromTypes(IEnumerable<IEdmSchemaType> types)
 {
     var model = new EdmModel();
     model.AddElements(types);
     return model;
 }
开发者ID:rossjempson,项目名称:odata.net,代码行数:6,代码来源:EdmEnumValueParserTests.cs

示例8: FindAllDerivedTypesWordsAcrossModels

        public void FindAllDerivedTypesWordsAcrossModels()
        {
            EdmModel model = new EdmModel();
            EdmModel referencedModel = new EdmModel();

            var A = new EdmEntityType("Referenced", "A");
            var AProp = A.AddStructuralProperty("ID", EdmCoreModel.Instance.GetString(false));
            A.AddKeys(new[] { AProp });

            var B = new EdmEntityType("Referenced", "B", A);
            var C = new EdmEntityType("Referenced", "C", B);

            var D = new EdmEntityType("Referenced", "D", C);

            referencedModel.AddElements(new[] { A, B, C });
            model.AddReferencedModel(referencedModel);
            model.AddElement(D);

            IEnumerable<IEdmStructuredType> derivedTypes = model.FindAllDerivedTypes(A);
            Assert.AreEqual(3, derivedTypes.Count(), "Correct number of derived types");
            Assert.IsTrue(derivedTypes.Contains(B), "Contains B");
            Assert.IsTrue(derivedTypes.Contains(C), "Contains C");
            Assert.IsTrue(derivedTypes.Contains(D), "Contains D");
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:24,代码来源:ExtensionMethodsTests.cs


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