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


C# EdmModel.SetAnnotationValue方法代码示例

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


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

示例1: BuildEdmModel

        public static IEdmModel BuildEdmModel(ODataModelBuilder builder)
        {
            if (builder == null)
            {
                throw Error.ArgumentNull("builder");
            }

            EdmModel model = new EdmModel();
            EdmEntityContainer container = new EdmEntityContainer(builder.Namespace, builder.ContainerName);

            // add types and sets, building an index on the way.
            Dictionary<Type, IEdmType> edmTypeMap = model.AddTypes(builder.StructuralTypes, builder.EnumTypes);
            Dictionary<string, EdmEntitySet> edmEntitySetMap = model.AddEntitySets(builder, container, edmTypeMap);

            // add procedures
            model.AddProcedures(builder.Procedures, container, edmTypeMap, edmEntitySetMap);

            // finish up
            model.AddElement(container);

            // build the map from IEdmEntityType to IEdmFunctionImport
            model.SetAnnotationValue<BindableProcedureFinder>(model, new BindableProcedureFinder(model));

            // set the data service version annotations.
            model.SetDataServiceVersion(builder.DataServiceVersion);
            model.SetMaxDataServiceVersion(builder.MaxDataServiceVersion);

            return model;
        }
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:29,代码来源:EdmModelHelperMethods.cs

示例2: ODataSingletonDeserializerTest

        public ODataSingletonDeserializerTest()
        {
            EdmModel model = new EdmModel();
            var employeeType = new EdmEntityType("NS", "Employee");
            employeeType.AddStructuralProperty("EmployeeId", EdmPrimitiveTypeKind.Int32);
            employeeType.AddStructuralProperty("EmployeeName", EdmPrimitiveTypeKind.String);
            model.AddElement(employeeType);

            EdmEntityContainer defaultContainer = new EdmEntityContainer("NS", "Default");
            model.AddElement(defaultContainer);

            _singleton = new EdmSingleton(defaultContainer, "CEO", employeeType);
            defaultContainer.AddElement(_singleton);

            model.SetAnnotationValue<ClrTypeAnnotation>(employeeType, new ClrTypeAnnotation(typeof(EmployeeModel)));

            _edmModel = model;
            _edmContainer = defaultContainer;

            _readContext = new ODataDeserializerContext
            {
                Path = new ODataPath(new SingletonPathSegment(_singleton)),
                Model = _edmModel,
                ResourceType = typeof(EmployeeModel)
            }; 

            _deserializerProvider = new DefaultODataDeserializerProvider();
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:28,代码来源:ODataSingletonDeserializerTest.cs

示例3: SetImmediateAnnotations

        private void SetImmediateAnnotations(IEdmElement edmAnnotatable, IEdmElement stockAnnotatable, IEdmModel edmModel, EdmModel stockModel)
        {
            IEnumerable<IEdmDirectValueAnnotation> annotations = edmModel.DirectValueAnnotations(edmAnnotatable);

            foreach (IEdmDirectValueAnnotation annotation in annotations)
            {
                var annotationValue = annotation.Value;
                string annotationNamespace = annotation.NamespaceUri;
                string annotationName = annotation.Name;
                stockModel.SetAnnotationValue(stockAnnotatable, annotationNamespace, annotationName, annotationValue);
            }
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:12,代码来源:EdmToStockModelConverter.cs

示例4: AnnotationWithoutChildrenModel

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

            EdmComplexType complexType = new EdmComplexType("DefaultNamespace", "ComplexType");
            complexType.AddStructuralProperty("Data", EdmCoreModel.Instance.GetString(true));
            model.AddElement(complexType);

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

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

示例5: BuildEdmModel

        public static IEdmModel BuildEdmModel(ODataModelBuilder builder)
        {
            if (builder == null)
            {
                throw Error.ArgumentNull("builder");
            }

            EdmModel model = new EdmModel();
            EdmEntityContainer container = new EdmEntityContainer(builder.Namespace, builder.ContainerName);

            // add types and sets, building an index on the way.
            IEnumerable<IEdmTypeConfiguration> configTypes = builder.StructuralTypes.Concat<IEdmTypeConfiguration>(builder.EnumTypes);
            EdmTypeMap edmMap = EdmTypeBuilder.GetTypesAndProperties(configTypes);
            Dictionary<Type, IEdmType> edmTypeMap = model.AddTypes(edmMap);

            // Add EntitySets and build the mapping between the EdmEntitySet and the NavigationSourceConfiguration
            NavigationSourceAndAnnotations[] entitySets = container.AddEntitySetAndAnnotations(builder, edmTypeMap);

            // Add Singletons and build the mapping between the EdmSingleton and the NavigationSourceConfiguration
            NavigationSourceAndAnnotations[] singletons = container.AddSingletonAndAnnotations(builder, edmTypeMap);

            // Merge EntitySets and Singletons together
            IEnumerable<NavigationSourceAndAnnotations> navigationSources = entitySets.Concat(singletons);

            // Build the navigation source map
            IDictionary<string, EdmNavigationSource> navigationSourceMap = model.GetNavigationSourceMap(builder, edmTypeMap, navigationSources);

            // Add the core vocabulary annotations
            model.AddCoreVocabularyAnnotations(entitySets, edmMap);

            // Add the capabilities vocabulary annotations
            model.AddCapabilitiesVocabularyAnnotations(entitySets, edmMap);

            // add procedures
            model.AddProcedures(builder.Procedures, container, edmTypeMap, navigationSourceMap);

            // finish up
            model.AddElement(container);

            // build the map from IEdmEntityType to IEdmFunctionImport
            model.SetAnnotationValue<BindableProcedureFinder>(model, new BindableProcedureFinder(model));

            return model;
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:44,代码来源:EdmModelHelperMethods.cs

示例6: SetNullAnnotationNameModel

        private static EdmModel SetNullAnnotationNameModel()
        {
            EdmModel model = new EdmModel();

            EdmEnumType spicy = new EdmEnumType("DefaultNamespace", "Spicy");
            model.AddElement(spicy);

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

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

示例7: AnnotationNameWhichIsNotSimpleIdentifierShouldPassValidation

        public void AnnotationNameWhichIsNotSimpleIdentifierShouldPassValidation()
        {
            var model = new EdmModel();
            model.SetEdmVersion(Microsoft.OData.Edm.Library.EdmConstants.EdmVersion4);
            var fredFlintstone = new EdmComplexType("Flintstones", "Fred");
            fredFlintstone.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false));
            model.AddElement(fredFlintstone);

            // set the annotation name to a value which is valid XML, but not a valid SimpleIdentifier.
            model.SetAnnotationValue(fredFlintstone, "sap", "content-version", new EdmStringConstant(EdmCoreModel.Instance.GetString(false), "hello"));

            Assert.AreEqual(1, model.DirectValueAnnotations(fredFlintstone).Count(), "Wrong # of Annotations on {0}.", fredFlintstone);

            IEnumerable<EdmError> errors;
            model.Validate(out errors);
            Assert.AreEqual(0, errors.Count(), "Model expected to be valid.");
        }
开发者ID:spawnadv,项目名称:msgraphodata.net,代码行数:17,代码来源:SemanticValidationTests.cs

示例8: OperationImportParameterWithAnnotationModel

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

            EdmEntityContainer container = new EdmEntityContainer("Default", "Container");
            EdmAction simpleOperationAction = new EdmAction("Default", "SimpleFunction", EdmCoreModel.Instance.GetInt32(false));
            EdmOperationParameter simpleOperationName = new EdmOperationParameter(simpleOperationAction, "Name", EdmCoreModel.Instance.GetString(true));
            simpleOperationAction.AddParameter(simpleOperationName);
            model.AddElement(simpleOperationAction);
            EdmOperationImport simpleOperation = new EdmActionImport(container, "SimpleFunction", simpleOperationAction);
            container.AddElement(simpleOperation);
            model.AddElement(container);

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

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

示例9: TestingDirectValueAnnotationsWithVariousConstantTypes

        public void TestingDirectValueAnnotationsWithVariousConstantTypes()
        {
            EdmModel model = new EdmModel();

            EdmEntityContainer container = new EdmEntityContainer("TestModel", "DefaultContainer");
            model.SetAnnotationValue(container, "http://foo.bar.com", "foo", new EdmBooleanConstant(EdmCoreModel.Instance.GetBoolean(false), true));
            model.SetAnnotationValue(container, "http://foo.bar.com", "bar", new EdmFloatingConstant(EdmCoreModel.Instance.GetDouble(false), 3.14));
            model.SetAnnotationValue(container, "http://foo.bar.com", "baz", new EdmGuidConstant(EdmCoreModel.Instance.GetGuid(false), new Guid("12345678-1234-1234-1234-123456781234")));
            model.SetAnnotationValue(container, "http://foo.bar.com", "ham", new EdmBinaryConstant(EdmCoreModel.Instance.GetBinary(false), new byte[] { 13, 14, 10, 13, 11, 14, 14, 15 }));
            model.SetAnnotationValue(container, "http://foo.bar.com", "spam", new EdmDecimalConstant(EdmCoreModel.Instance.GetDecimal(false), (decimal)3.50));
            model.SetAnnotationValue(container, "http://foo.bar.com", "spum", new EdmDateTimeOffsetConstant(EdmCoreModel.Instance.GetDateTimeOffset(false), new DateTimeOffset(2001, 1, 1, 5, 40, 00, new TimeSpan(5, 4, 0))));
            model.SetAnnotationValue(container, "http://foo.bar.com", "spork", new EdmDurationConstant(EdmCoreModel.Instance.GetDuration(false), new TimeSpan(5, 4, 3)));

            model.AddElement(container);

            IEnumerable<XElement> csdl = new []{XElement.Parse(
@"<Schema Namespace=""TestModel"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
    <EntityContainer Name=""DefaultContainer"" p2:bar=""3.14"" p2:baz=""12345678-1234-1234-1234-123456781234"" p2:foo=""true"" p2:ham=""0D0E0A0D0B0E0E0F"" p2:spam=""3.5"" p2:spork=""PT5H4M3S"" p2:spum=""2001-01-01T05:40:00+05:04"" xmlns:p2=""http://foo.bar.com"" />
</Schema>", LoadOptions.SetLineInfo)};

            this.BasicConstructibleModelTestSerializingStockModel(csdl, model);
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:22,代码来源:ConstructibleModelTestsUsingConverter.cs

示例10: ToDictionary_ContainsAllStructuralProperties_IfInstanceIsNotNull

        public void ToDictionary_ContainsAllStructuralProperties_IfInstanceIsNotNull()
        {
            // Arrange
            EdmModel model = new EdmModel();
            EdmEntityType entityType = new EdmEntityType("NS", "Name");
            model.AddElement(entityType);
            model.SetAnnotationValue(entityType, new ClrTypeAnnotation(typeof(TestEntity)));
            entityType.AddStructuralProperty("SampleProperty", EdmPrimitiveTypeKind.Int32);
            IEdmTypeReference edmType = new EdmEntityTypeReference(entityType, isNullable: false);
            SelectExpandWrapper<TestEntity> testWrapper = new SelectExpandWrapper<TestEntity>
            {
                Instance = new TestEntity { SampleProperty = 42 },
                ModelID = ModelContainer.GetModelID(model)
            };

            // Act
            var result = testWrapper.ToDictionary();

            // Assert
            Assert.Equal(42, result["SampleProperty"]);
        }
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:21,代码来源:SelectExpandWrapperTest.cs

示例11: CustomersModelWithInheritance


//.........这里部分代码省略.........
                "NS",
                "GetCustomer",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            entityFunction.AddParameter("entity", new EdmEntityTypeReference(customer, false));
            entityFunction.AddParameter("customer", new EdmEntityTypeReference(customer, false));
            model.AddElement(entityFunction);

            EdmFunction getOrder = new EdmFunction(
                "NS",
                "GetOrder",
                order.ToEdmTypeReference(false),
                isBound: true,
                entitySetPathExpression: null,
                isComposable: true); // Composable
            getOrder.AddParameter("entity", new EdmEntityTypeReference(customer, false));
            getOrder.AddParameter("orderId", intType);
            model.AddElement(getOrder);

            // functions bound to collection
            EdmFunction isAllUpgraded = new EdmFunction("NS", "IsAllUpgraded", returnType, isBound: true,
                entitySetPathExpression: null, isComposable: false);
            isAllUpgraded.AddParameter("entityset",
                new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(customer, false))));
            isAllUpgraded.AddParameter("param", intType);
            model.AddElement(isAllUpgraded);

            EdmFunction isSpecialAllUpgraded = new EdmFunction("NS", "IsSpecialAllUpgraded", returnType, isBound: true,
                entitySetPathExpression: null, isComposable: false);
            isSpecialAllUpgraded.AddParameter("entityset",
                new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(specialCustomer, false))));
            isSpecialAllUpgraded.AddParameter("param", intType);
            model.AddElement(isSpecialAllUpgraded);

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

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

            // set properties
            Model = model;
            Container = container;
            Customer = customer;
            Order = order;
            Address = address;
            Account = account;
            SpecialCustomer = specialCustomer;
            SpecialOrder = specialOrder;
            Orders = orders;
            Customers = customers;
            VipCustomer = vipCustomer;
            Mary = mary;
            RootOrder = rootOrder;
            OrderLine = orderLine;
            OrderLines = orderLines; 
            NonContainedOrderLines = nonContainedOrderLines;
            UpgradeCustomer = upgrade;
            UpgradeSpecialCustomer = specialUpgrade;
            CustomerName = customerName;
            IsCustomerUpgraded = isCustomerUpgradedWithParam;
            IsSpecialCustomerUpgraded = IsSpecialUpgraded;
            Tag = tag;
        }
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:101,代码来源:CustomersModelWithInheritance.cs

示例12: GetEnumModel

        private static IEdmModel GetEnumModel()
        {
            EdmModel model = new EdmModel();

            EdmEnumType enumType = new EdmEnumType("TestModel", "TestEnum");
            enumType.AddMember(new EdmEnumMember(enumType, "FirstValue", new EdmIntegerConstant(0)));
            enumType.AddMember(new EdmEnumMember(enumType, "FirstValue", new EdmIntegerConstant(1)));
            model.AddElement(enumType);

            model.SetAnnotationValue(model.FindDeclaredType("TestModel.TestEnum"), new ClrTypeAnnotation(typeof(TestEnum)));

            return model;
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:13,代码来源:DefaultODataSerializerProviderTests.cs

示例13: CsdlWriterShouldFailWithGoodMessageWhenWritingInvalidXml

        public void CsdlWriterShouldFailWithGoodMessageWhenWritingInvalidXml()
        {
            var model = new EdmModel();
            model.SetEdmVersion(Microsoft.OData.Edm.Library.EdmConstants.EdmVersion4);
            var fredFlintstone = new EdmComplexType("Flintstones", "Fred");
            fredFlintstone.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false));
            model.AddElement(fredFlintstone);

            // set annotation which will be serialzed (because the value is an IEdmValue) with a name that doesn't match the xml spec for NCName.
            model.SetAnnotationValue(fredFlintstone, "sap", "-contentversion", new EdmStringConstant(EdmCoreModel.Instance.GetString(false), "hello"));

            Assert.AreEqual(1, model.DirectValueAnnotations(fredFlintstone).Count(), "Wrong # of Annotations on {0}.", fredFlintstone);

            var stringWriter = new StringWriter();
            var xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings() { Indent = true });

            try
            {
                IEnumerable<EdmError> errors;
                model.TryWriteCsdl(xmlWriter, out errors);
                Assert.Fail("Excepted an exception when trying to serialize a direct value annotation which does not match the xml naming spec.");
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(e.Message, "Invalid name character in '-contentversion'. The '-' character, hexadecimal value 0x2D, cannot be included in a name.", "Expected exception message did not match.");
            }

            xmlWriter.Close();
        }
开发者ID:spawnadv,项目名称:msgraphodata.net,代码行数:29,代码来源:SemanticValidationTests.cs

示例14: NestedXElementWithNoValueModel

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

            EdmComplexType simpleType = new EdmComplexType("DefaultNamespace", "SimpleType");
            EdmStructuralProperty simpleTypeId = simpleType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(true));
            model.AddElement(simpleType);

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

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

示例15: SetChildAnnotationAsAnnotationModel

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

            EdmTerm note = new EdmTerm("DefaultNamespace", "Note", EdmPrimitiveTypeKind.Int16);
            model.AddElement(note);

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

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


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