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


C# EdmModel.AddElement方法代码示例

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


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

示例1: CreateCustomerProductsModel

        private static EdmModel CreateCustomerProductsModel()
        {
            var model = new EdmModel();

            var container = new EdmEntityContainer("defaultNamespace", "DefaultContainer");
            model.AddElement(container);

            var productType = new EdmEntityType("defaultNamespace", "Product");
            model.AddElement(productType);

            var customerType = new EdmEntityType("defaultNamespace", "Customer");
            customerType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Products", Target = productType, TargetMultiplicity = EdmMultiplicity.Many });
            productType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Customers", Target = customerType, TargetMultiplicity = EdmMultiplicity.Many });

            model.AddElement(customerType);

            var productSet = new EdmEntitySet(
                container,
                "Products",
                productType);

            container.AddElement(productSet);

            var customerSet = new EdmEntitySet(
                container,
                "Customers",
                customerType);

            var productsNavProp = customerType.NavigationProperties().Single(np => np.Name == "Products");
            customerSet.AddNavigationTarget(productsNavProp, productSet);
            container.AddElement(customerSet);

            return model;
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:34,代码来源:ODataUriHelperTest.cs

示例2: SimpleCustomerOrderModel

        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
            });

            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);

            EntitySetLinkBuilderAnnotation linkAnnotation = new MockEntitySetLinkBuilderAnnotation();
            model.SetEntitySetLinkBuilder(customerSet, linkAnnotation);
            model.SetEntitySetLinkBuilder(orderSet, linkAnnotation);

            model.AddElement(container);
            return model;
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:54,代码来源:SerializationTestsHelpers.cs

示例3: TableStorageQueryIndexInspector

        static TableStorageQueryIndexInspector()
        {
            EdmModel = new EdmModel();
            TableServiceEntity = new EdmEntityType("Glimpse.WindowsAzure.Storage", "TableServiceEntity");
            TableServiceEntity.AddStructuralProperty("PartitionKey", EdmPrimitiveTypeKind.String);
            TableServiceEntity.AddStructuralProperty("RowKey", EdmPrimitiveTypeKind.String);
            TableServiceEntity.AddStructuralProperty("Timestamp", EdmPrimitiveTypeKind.DateTime);
            EdmModel.AddElement(TableServiceEntity);

            var container = new EdmEntityContainer("TestModel", "DefaultContainer");
            container.AddEntitySet("Entities", TableServiceEntity);
            EdmModel.AddElement(container);
        }
开发者ID:jeffora,项目名称:Glimpse,代码行数:13,代码来源:TableStorageQueryIndexInspector.cs

示例4: 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, IEdmStructuredType> edmTypeMap = model.AddTypes(builder.StructuralTypes);
            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));

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

示例5: ConvertToEdmEntityType

        private EdmEntityType ConvertToEdmEntityType(JSchema schema, EdmModel model, string name)
        {
            var type = new EdmEntityType("namespace", name);

            foreach (var property in schema.Properties)
            {
                if (property.Value.Type == null)
                    throw new Exception("Type specyfication missing.");

                var structuralType = MapPropertyToStructuralType(property, schema, model);

                if (structuralType != null)
                {
                    type.AddStructuralProperty(property.Key, structuralType);
                }
                else
                {
                    type.AddStructuralProperty(property.Key, ToEdmPrimitiveType(property.Value.Type.Value));
                }
            }

            model.AddElement(type);

            return type;
        }
开发者ID:terianil,项目名称:JsonSchemaToEdmModel,代码行数:25,代码来源:JsonSchemaConverter.cs

示例6: SimpleCustomerOrderModel

        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);
            model.AddElement(customerType);

            var orderType = new EdmEntityType("Default", "Order");
            orderType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32);
            orderType.AddStructuralProperty("Name", 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 });

            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);

            Mock<IEntitySetLinkBuilder> linkAnnotation = new Mock<IEntitySetLinkBuilder>();
            model.SetEntitySetLinkBuilderAnnotation(customerSet, linkAnnotation.Object);
            model.SetEntitySetLinkBuilderAnnotation(orderSet, linkAnnotation.Object);

            model.AddElement(container);
            return model;
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:39,代码来源:SerializationTestsHelpers.cs

示例7: ToEdmModel

        public IEdmModel ToEdmModel(JSchema schema)
        {
            var model = new EdmModel();

            var container = new EdmEntityContainer("namespace", "containerName");

            var rootType = ConvertToEdmEntityType(schema, model, "root");

            container.AddEntitySet("root", rootType);
            model.AddElement(container);

            return model;
        }
开发者ID:terianil,项目名称:JsonSchemaToEdmModel,代码行数:13,代码来源:JsonSchemaConverter.cs

示例8: BuildModel

        public IEdmModel BuildModel(IEnumerable<TableData> tables)
        {
            var model = new EdmModel();            
            var container = new EdmEntityContainer("sitecore.com", "Visits");
            model.AddElement(container);            
            

            var tableMap = new Dictionary<TableDataSchema, EdmEntityTypeWrapper>();
            foreach (var table in tables)
            {
                var typeWrapper = AddTable(model, table);
                container.AddEntitySet(table.Name, typeWrapper.Type);
                tableMap.Add(table.Schema, typeWrapper);
            }

            foreach (var t in tableMap)
            {
                foreach (var reference in t.Key.RelatedTables)
                {
                    if (reference.RelationType == RelationType.Child || reference.RelationType == RelationType.DimensionReference)
                    {
                        var source = t.Value;
                        var target = tableMap[reference.RelatedTable];
                                                

                        t.Value.Type.AddBidirectionalNavigation(new EdmNavigationPropertyInfo()
                        {
                            Name = reference.RelatedTable.Name,
                            TargetMultiplicity = EdmMultiplicity.Many,                            
                            Target = target.Type
                        }, new EdmNavigationPropertyInfo()
                        {
                            Name = t.Key.Name,
                            TargetMultiplicity = reference.RelationType == RelationType.Child ? EdmMultiplicity.One : EdmMultiplicity.ZeroOrOne,
                            DependentProperties = reference.RelatedFields.Select(f=>target.Properties[f]),
                            Target = source.Type
                        });
                    }
                }
            }

            return model;
        }
开发者ID:vsegrad,项目名称:experience-extractor,代码行数:43,代码来源:EdmSchemaBuilder.cs

示例9: EntityContainer_Is_Default_ShowsUp_In_Metadata

        public void EntityContainer_Is_Default_ShowsUp_In_Metadata()
        {
            // Arrange
            EdmModel model = new EdmModel();
            EdmEntityContainer container = new EdmEntityContainer("Default", "SampleContainer");
            model.AddElement(container);

            // Act
            model.SetIsDefaultEntityContainer(container, isDefaultContainer: true);

            // Assert
            MemoryStream stream = new MemoryStream();
            ODataMessageWriter writer = new ODataMessageWriter(new ODataMessageWrapper(stream) as IODataResponseMessage, new ODataMessageWriterSettings(), model);
            writer.WriteMetadataDocument();
            stream.Seek(0, SeekOrigin.Begin);
            XElement element = XElement.Load(stream);
            var containerXml = element.Descendants().Where(n => n.Name.LocalName == "EntityContainer").SingleOrDefault();
            Assert.Equal("SampleContainer", containerXml.Attribute("Name").Value);
            Assert.Equal("true", containerXml.Attributes().Where(a => a.Name.LocalName == "IsDefaultEntityContainer").Single().Value);
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:20,代码来源:ODataUtilsLearningTests.cs

示例10: 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<string, IEdmStructuredType> edmTypeMap = model.AddTypes(builder.StructuralTypes);
            Dictionary<string, EdmEntitySet> edmEntitySetMap = model.AddEntitySets(builder.EntitySets, container, edmTypeMap);
            
            // add procedures
            container.AddProcedures(builder.Procedures, edmTypeMap, edmEntitySetMap);

            // finish up
            model.AddElement(container);
            return model;
        }
开发者ID:mikevpeters,项目名称:aspnetwebstack,代码行数:21,代码来源:EdmModelHelperMethods.cs

示例11: BuildModel

        private static IEdmModel BuildModel(JObject viewObject, out IList<string> fieldsToIgnore)
        {
            var model = new EdmModel();
            fieldsToIgnore = new List<string>();

            var name = viewObject.PrimitivePropertyValue<string>("name");
            name = name.Replace(' ', '_');

            var entityType = new EdmEntityType(false, false, null, "OData4Socrata", name,
                                               Enumerable.Empty<IEdmStructuralProperty>());
            var entitySet = new EdmEntitySet(name, entityType);

            EdmComplexType phoneComplex = null;
            EdmComplexType locationComplex = null;
            EdmComplexType urlComplex = null;

            foreach (var column in viewObject.ArrayPropertyValue<JObject>("columns"))
            {
                var fieldName = column.PrimitivePropertyValue<string>("name");

                var sodaType = column.PrimitivePropertyValue<string>("dataTypeName");
                IEdmTypeReference typeReference;
                switch (sodaType)
                {
                    case "meta_data":
                        fieldsToIgnore.Add(fieldName);
                        continue;

                    case "text":

                        typeReference = EdmLibraryExtensions.GetPrimitiveTypeReference(typeof (string));
                        break;

                    case "url":
                        if (urlComplex == null)
                        {
                            urlComplex = new EdmComplexType(false, false, null, entityType.Namespace, "url");
                            new EdmStructuralProperty(urlComplex, "url", EdmLibraryExtensions.GetPrimitiveTypeReference(typeof (string)),
                                                      null, EdmConcurrencyMode.None);
                            model.AddElement(urlComplex);
                        }

                        typeReference = new EdmComplexTypeReference(urlComplex, false);
                        break;

                    case "phone":
                        if (phoneComplex == null)
                        {
                            phoneComplex = new EdmComplexType(false, false, null, entityType.Namespace, "phone");
                            new EdmStructuralProperty(phoneComplex, "phone_number",
                                                      EdmLibraryExtensions.GetPrimitiveTypeReference(typeof (string)), null,
                                                      EdmConcurrencyMode.None);
                            new EdmStructuralProperty(phoneComplex, "phone_type",
                                                      EdmLibraryExtensions.GetPrimitiveTypeReference(typeof (string)), null,
                                                      EdmConcurrencyMode.None);
                            model.AddElement(phoneComplex);
                        }

                        typeReference = new EdmComplexTypeReference(phoneComplex, false);
                        break;

                    case "location":
                        if (locationComplex == null)
                        {
                            locationComplex = new EdmComplexType(false, false, null, entityType.Namespace, "location");
                            new EdmStructuralProperty(locationComplex, "human_address",
                                                      EdmLibraryExtensions.GetPrimitiveTypeReference(typeof (string)), null,
                                                      EdmConcurrencyMode.None);
                            new EdmStructuralProperty(locationComplex, "latitude",
                                                      EdmLibraryExtensions.GetPrimitiveTypeReference(typeof (string)), null,
                                                      EdmConcurrencyMode.None);
                            new EdmStructuralProperty(locationComplex, "longitude",
                                                      EdmLibraryExtensions.GetPrimitiveTypeReference(typeof (string)), null,
                                                      EdmConcurrencyMode.None);
                            new EdmStructuralProperty(locationComplex, "machine_address",
                                                      EdmLibraryExtensions.GetPrimitiveTypeReference(typeof (string)), null,
                                                      EdmConcurrencyMode.None);
                            new EdmStructuralProperty(locationComplex, "needs_recoding",
                                                      EdmLibraryExtensions.GetPrimitiveTypeReference(typeof (bool)), null,
                                                      EdmConcurrencyMode.None);
                            model.AddElement(locationComplex);
                        }

                        typeReference = new EdmComplexTypeReference(locationComplex, false);
                        break;

                    default:
                        throw new Exception();
                }

                new EdmStructuralProperty(entityType, fieldName, typeReference, null, EdmConcurrencyMode.None);
            }

            model.AddElement(entityType);

            var entityContainer = new EdmEntityContainer();
            model.AddEntityContainer(entityContainer);
            entityContainer.AddElement(entitySet);

            return model;
//.........这里部分代码省略.........
开发者ID:OData,项目名称:OData4Soda,代码行数:101,代码来源:SodaToODataConverter.cs

示例12: AddTable

        EdmEntityTypeWrapper AddTable(EdmModel model, TableData dataBuilder)
        {
            var propertyMap = new Dictionary<Field, EdmStructuralProperty>();

            var table = new EdmEntityType("sitecore.com", dataBuilder.Name);
            foreach (var field in dataBuilder.Schema.Fields)
            {
                var prop = table.AddStructuralProperty(field.Name, GetEdmType(field.ValueType), IsNullable(field.ValueType));                
                if (field.FieldType == FieldType.Key)
                {
                    table.AddKeys(prop);
                }
                propertyMap.Add(field, prop);
            }            
            model.AddElement(table);            

            return new EdmEntityTypeWrapper {Type = table, Properties = propertyMap};
        }
开发者ID:vsegrad,项目名称:experience-extractor,代码行数:18,代码来源:EdmSchemaBuilder.cs

示例13: ToDictionary_AppliesMappingToAllProperties_IfInstanceIsNotNull

        public void ToDictionary_AppliesMappingToAllProperties_IfInstanceIsNotNull()
        {
            // Arrange
            EdmEntityType entityType = new EdmEntityType("NS", "Name");
            entityType.AddStructuralProperty("SampleProperty", EdmPrimitiveTypeKind.Int32);

            EdmModel model = new EdmModel();
            model.AddElement(entityType);
            model.SetAnnotationValue(entityType, new ClrTypeAnnotation(typeof(TestEntity)));
            IEdmTypeReference edmType = new EdmEntityTypeReference(entityType, isNullable: false);

            SelectExpandWrapper<TestEntity> testWrapper = new SelectExpandWrapper<TestEntity>
            {
                Instance = new TestEntity { SampleProperty = 42 },
                ModelID = ModelContainer.GetModelID(model)
            };

            Mock<IPropertyMapper> mapperMock = new Mock<IPropertyMapper>();
            mapperMock.Setup(m => m.MapProperty("SampleProperty")).Returns("Sample");
            Func<IEdmModel, IEdmStructuredType, IPropertyMapper> mapperProvider =
                (IEdmModel m, IEdmStructuredType t) => mapperMock.Object;

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

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

示例14: CreateTypeNameExpression_ReturnsConditionalExpression_IfTypeHasDerivedTypes

        public void CreateTypeNameExpression_ReturnsConditionalExpression_IfTypeHasDerivedTypes()
        {
            // Arrange
            IEdmEntityType baseType = new EdmEntityType("NS", "BaseType");
            IEdmEntityType typeA = new EdmEntityType("NS", "A", baseType);
            IEdmEntityType typeB = new EdmEntityType("NS", "B", baseType);
            IEdmEntityType typeAA = new EdmEntityType("NS", "AA", typeA);
            IEdmEntityType typeAAA = new EdmEntityType("NS", "AAA", typeAA);
            IEdmEntityType[] types = new[] { baseType, typeA, typeAAA, typeB, typeAA };

            EdmModel model = new EdmModel();
            foreach (var type in types)
            {
                model.AddElement(type);
                model.SetAnnotationValue(type, new ClrTypeAnnotation(new MockType(type.Name, @namespace: type.Namespace)));
            }

            Expression source = Expression.Constant(42);

            // Act
            Expression result = SelectExpandBinder.CreateTypeNameExpression(source, baseType, model);

            // Assert
            Assert.Equal(
                result.ToString(),
                @"IIF((42 Is AAA), ""NS.AAA"", IIF((42 Is AA), ""NS.AA"", IIF((42 Is B), ""NS.B"", IIF((42 Is A), ""NS.A"", ""NS.BaseType""))))");
        }
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:27,代码来源:SelectExpandBinderTest.cs

示例15: Property_EntityInstance_EdmObjectHasCollectionProperty

        public void Property_EntityInstance_EdmObjectHasCollectionProperty()
        {
            // Arrange
            EdmEntityType edmType = new EdmEntityType("NS", "Name");
            edmType.AddStructuralProperty(
                "CollectionProperty",
                new EdmCollectionTypeReference(
                    new EdmCollectionType(EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: false)), isNullable: false));
            EdmModel model = new EdmModel();
            model.AddElement(edmType);
            model.SetAnnotationValue<ClrTypeAnnotation>(edmType, new ClrTypeAnnotation(typeof(TestEntity)));
            Mock<IEdmStructuredObject> edmObject = new Mock<IEdmStructuredObject>();
            object propertyValue = new List<int> { 42 };
            edmObject.Setup(e => e.TryGetValue("CollectionProperty", out propertyValue)).Returns(true);
            edmObject.Setup(e => e.GetEdmType()).Returns(new EdmEntityTypeReference(edmType, isNullable: false));

            EntityInstanceContext entityContext = new EntityInstanceContext { EdmModel = model, EdmObject = edmObject.Object, EntityType = edmType };

            // Act
            object resource = entityContext.EntityInstance;

            // Assert
            TestEntity testEntity = Assert.IsType<TestEntity>(resource);
            Assert.Equal(new[] { 42 }, testEntity.CollectionProperty);
        }
开发者ID:karensyc,项目名称:aspnetwebstack,代码行数:25,代码来源:EntityInstanceContextTest.cs


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