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


C# EdmEntityContainer.AddEntitySet方法代码示例

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


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

示例1: GetEdmModel

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

            // Create and add product entity type.
            EdmEntityType product = new EdmEntityType("NS", "Product");
            product.AddKeys(product.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
            product.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            product.AddStructuralProperty("Price", EdmPrimitiveTypeKind.Double);
            model.AddElement(product);

            // Create and add category entity type.
            EdmEntityType category = new EdmEntityType("NS", "Category");
            category.AddKeys(category.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
            category.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            model.AddElement(category);

            // Set navigation from product to category.
            EdmNavigationPropertyInfo propertyInfo = new EdmNavigationPropertyInfo();
            propertyInfo.Name = "Category";
            propertyInfo.TargetMultiplicity = EdmMultiplicity.One;
            propertyInfo.Target = category;
            EdmNavigationProperty productCategory = product.AddUnidirectionalNavigation(propertyInfo);

            // Create and add entity container.
            EdmEntityContainer container = new EdmEntityContainer("NS", "DefaultContainer");
            model.AddElement(container);

            // Create and add entity set for product and category.
            EdmEntitySet products = container.AddEntitySet("Products", product);
            EdmEntitySet categories = container.AddEntitySet("Categories", category);
            products.AddNavigationTarget(productCategory, categories);

            return model;
        }
开发者ID:nickgoodrow,项目名称:ODataSamples,代码行数:35,代码来源:ODataUntypedSample.cs

示例2: GetModel

        public void GetModel(EdmModel model, EdmEntityContainer container)
        {
            EdmEntityType student = new EdmEntityType("ns", "Student");
            student.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            EdmStructuralProperty key = student.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32);
            student.AddKeys(key);
            model.AddElement(student);
            EdmEntitySet students = container.AddEntitySet("Students", student);

            EdmEntityType school = new EdmEntityType("ns", "School");
            school.AddKeys(school.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
            school.AddStructuralProperty("CreatedDay", EdmPrimitiveTypeKind.DateTimeOffset);
            model.AddElement(school);
            EdmEntitySet schools = container.AddEntitySet("Schools", student);

            EdmNavigationProperty schoolNavProp = student.AddUnidirectionalNavigation(
                new EdmNavigationPropertyInfo
                {
                    Name = "School",
                    TargetMultiplicity = EdmMultiplicity.One,
                    Target = school
                });
            students.AddNavigationTarget(schoolNavProp, schools);

            _school = school;
        }
开发者ID:chinadragon0515,项目名称:ODataSamples,代码行数:26,代码来源:AnotherDataSource.cs

示例3: GetEdmModel

        public static IEdmModel GetEdmModel()
        {
            if (_edmModel != null)
            {
                return _edmModel;
            }

            EdmModel model = new EdmModel();

            // entity type 'Customer' with single alternate keys
            EdmEntityType customer = new EdmEntityType("NS", "Customer");
            customer.AddKeys(customer.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
            customer.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            var ssn = customer.AddStructuralProperty("SSN", EdmPrimitiveTypeKind.String);
            model.AddAlternateKeyAnnotation(customer, new Dictionary<string, IEdmProperty>
            {
                {"SSN", ssn}
            });
            model.AddElement(customer);

            // entity type 'Order' with multiple alternate keys
            EdmEntityType order = new EdmEntityType("NS", "Order");
            order.AddKeys(order.AddStructuralProperty("OrderId", EdmPrimitiveTypeKind.Int32));
            var orderName = order.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            var orderToken = order.AddStructuralProperty("Token", EdmPrimitiveTypeKind.Guid);
            order.AddStructuralProperty("Amount", EdmPrimitiveTypeKind.Int32);
            model.AddAlternateKeyAnnotation(order, new Dictionary<string, IEdmProperty>
            {
                {"Name", orderName}
            });

            model.AddAlternateKeyAnnotation(order, new Dictionary<string, IEdmProperty>
            {
                {"Token", orderToken}
            });

            model.AddElement(order);

            // entity type 'Person' with composed alternate keys
            EdmEntityType person = new EdmEntityType("NS", "Person");
            person.AddKeys(person.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
            var country = person.AddStructuralProperty("Country", EdmPrimitiveTypeKind.String);
            var passport = person.AddStructuralProperty("Passport", EdmPrimitiveTypeKind.String);
            model.AddAlternateKeyAnnotation(person, new Dictionary<string, IEdmProperty>
            {
                {"Country", country},
                {"Passport", passport}
            });
            model.AddElement(person);

            // entity sets
            EdmEntityContainer container = new EdmEntityContainer("NS", "Default");
            model.AddElement(container);
            container.AddEntitySet("Customers", customer);
            container.AddEntitySet("Orders", order);
            container.AddEntitySet("People", person);

            return _edmModel = model;
        }
开发者ID:nickgoodrow,项目名称:ODataSamples,代码行数:59,代码来源:AlternateKeyEdmModel.cs

示例4: CreateTestModel

 private static EdmModel CreateTestModel()
 {
     var objectType = new EdmEntityType("DefaultNamespace", "Object");
     var personType = new EdmEntityType("DefaultNamespace", "Person", objectType);
     var container = new EdmEntityContainer("DefaultNamespace", "Container");
     container.AddEntitySet("Objects", objectType);
     container.AddEntitySet("People", personType);
     var model = new EdmModel();
     model.AddElement(objectType);
     model.AddElement(personType);
     model.AddElement(container);
     return model;
 }
开发者ID:larsenjo,项目名称:odata.net,代码行数:13,代码来源:ODataWriterCoreTests.cs

示例5: ExapndOptionFunctionalTests

        static ExapndOptionFunctionalTests()
        {
            string namespaceA = "NS";
            EdmModel edmModel = new EdmModel();
            EdmEntityType type1 = new EdmEntityType(namespaceA, "T1");
            EdmEntityType type2 = new EdmEntityType(namespaceA, "T2", type1);
            EdmEntityType type3 = new EdmEntityType(namespaceA, "T3", type2);
            EdmNavigationProperty nav21 = type2.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "Nav21",
                ContainsTarget = false,
                Target = type1,
                TargetMultiplicity = EdmMultiplicity.ZeroOrOne,
            });

            EdmNavigationProperty nav22 = type2.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "Nav22",
                ContainsTarget = false,
                Target = type2,
                TargetMultiplicity = EdmMultiplicity.One,
            });

            EdmNavigationProperty nav23 = type2.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "Nav23",
                ContainsTarget = false,
                Target = type3,
                TargetMultiplicity = EdmMultiplicity.Many,
            });

            
            edmModel.AddElement(type1);
            edmModel.AddElement(type2);
            edmModel.AddElement(type3);

            EdmEntityContainer container = new EdmEntityContainer(namespaceA, "Con1");
            var set1 = container.AddEntitySet(namespaceA, type1);
            var set2 = container.AddEntitySet(namespaceA, type2);
            var set3 = container.AddEntitySet(namespaceA, type3);
            edmModel.AddElement(container);
            set2.AddNavigationTarget(nav21, set1);
            set2.AddNavigationTarget(nav22, set2);
            set2.AddNavigationTarget(nav23, set3);

            Model = edmModel;
            T2Type = type2;
            T3Type = type3;
            T2Set = set2;
            T3Set = set3;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:51,代码来源:ExapndOptionFunctionalTests.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);
            IEdmTypeReference primitiveTypeReference = EdmCoreModel.Instance.GetPrimitive(
                EdmPrimitiveTypeKind.String,
                isNullable: true);
            customerType.AddStructuralProperty(
                "City",
                primitiveTypeReference,
                defaultValue: null,
                concurrencyMode: EdmConcurrencyMode.Fixed);
            model.AddElement(customerType);

            var orderType = new EdmEntityType("Default", "Order");
            orderType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32);
            orderType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            orderType.AddStructuralProperty("Shipment", EdmPrimitiveTypeKind.String);
            model.AddElement(orderType);

            var addressType = new EdmComplexType("Default", "Address");
            addressType.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String);
            addressType.AddStructuralProperty("City", EdmPrimitiveTypeKind.String);
            addressType.AddStructuralProperty("State", EdmPrimitiveTypeKind.String);
            addressType.AddStructuralProperty("Country", EdmPrimitiveTypeKind.String);
            addressType.AddStructuralProperty("ZipCode", EdmPrimitiveTypeKind.String);
            model.AddElement(addressType);

            // Add navigations
            customerType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Orders", Target = orderType, TargetMultiplicity = EdmMultiplicity.Many });
            orderType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Customer", Target = customerType, TargetMultiplicity = EdmMultiplicity.One });

            // Add Entity set
            var container = new EdmEntityContainer("Default", "Container");
            var customerSet = container.AddEntitySet("Customers", customerType);
            var orderSet = container.AddEntitySet("Orders", orderType);
            customerSet.AddNavigationTarget(customerType.NavigationProperties().Single(np => np.Name == "Orders"), orderSet);
            orderSet.AddNavigationTarget(orderType.NavigationProperties().Single(np => np.Name == "Customer"), customerSet);

            NavigationSourceLinkBuilderAnnotation linkAnnotation = new MockNavigationSourceLinkBuilderAnnotation();
            model.SetNavigationSourceLinkBuilder(customerSet, linkAnnotation);
            model.SetNavigationSourceLinkBuilder(orderSet, linkAnnotation);

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

示例7: WriterTypeNameEndToEndTests

        public WriterTypeNameEndToEndTests()
        {
            var model = new EdmModel();
            var type = new EdmEntityType("TestModel", "TestEntity", /* baseType */ null, /* isAbstract */ false, /* isOpen */ true);
            var keyProperty = type.AddStructuralProperty("DeclaredInt16", EdmPrimitiveTypeKind.Int16);
            type.AddKeys(new[] { keyProperty });

            // Note: DerivedPrimitive is declared as a Geography, but its value below will be set to GeographyPoint, which is derived from Geography.
            type.AddStructuralProperty("DerivedPrimitive", EdmPrimitiveTypeKind.Geography);
            var container = new EdmEntityContainer("TestModel", "Container");
            var set = container.AddEntitySet("Set", type);
            model.AddElement(type);
            model.AddElement(container);

            var writerStream = new MemoryStream();
            this.settings = new ODataMessageWriterSettings();
            this.settings.SetServiceDocumentUri(ServiceDocumentUri);

            // Make the message writer and entry writer lazy so that individual tests can tweak the settings before the message writer is created.
            this.messageWriter = new Lazy<ODataMessageWriter>(() =>
                new ODataMessageWriter(
                    (IODataResponseMessage)new InMemoryMessage { Stream = writerStream },
                    this.settings,
                    model));

            var entryWriter = new Lazy<ODataWriter>(() => this.messageWriter.Value.CreateODataEntryWriter(set, type));

            var valueWithAnnotation = new ODataPrimitiveValue(45);
            valueWithAnnotation.SetAnnotation(new SerializationTypeNameAnnotation { TypeName = "TypeNameFromSTNA" });

            var propertiesToWrite = new List<ODataProperty>
            {
                new ODataProperty
                {
                    Name = "DeclaredInt16", Value = (Int16)42
                }, 
                new ODataProperty
                {
                    Name = "UndeclaredDecimal", Value = (Decimal)4.5
                }, 
                new ODataProperty
                {
                    // Note: value is more derived than the declared type.
                    Name = "DerivedPrimitive", Value = Microsoft.Spatial.GeographyPoint.Create(42, 45)
                },
                new ODataProperty()
                {
                    Name = "PropertyWithSTNA", Value = valueWithAnnotation
                }
            };

            this.writerOutput = new Lazy<string>(() =>
            {
                entryWriter.Value.WriteStart(new ODataEntry { Properties = propertiesToWrite });
                entryWriter.Value.WriteEnd();
                entryWriter.Value.Flush();
                writerStream.Seek(0, SeekOrigin.Begin);
                return new StreamReader(writerStream).ReadToEnd();
            });
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:60,代码来源:WriterTypeNameEndToEndTests.cs

示例8: GetModel

 public void GetModel(EdmModel model, EdmEntityContainer container)
 {
     EdmEntityType product = new EdmEntityType("ns", "Student");
     product.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
     EdmStructuralProperty key = product.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32);
     product.AddKeys(key);
     model.AddElement(product);
     container.AddEntitySet("Students", product);
 }
开发者ID:nickgoodrow,项目名称:ODataSamples,代码行数:9,代码来源:AnotherDataSource.cs

示例9: JsonLightTypeResolverTests

        public JsonLightTypeResolverTests()
        {
            this.serverModel = new EdmModel();
            var serverEntityType = new EdmEntityType("Server.Name.Space", "EntityType");
            serverEntityType.AddKeys(serverEntityType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
            var parentType = new EdmEntityType("Server.Name.Space", "Parent");
            this.serverModel.AddElement(serverEntityType);
            this.serverModel.AddElement(parentType);

            var serverComplexType = new EdmComplexType("Server.Name.Space", "ComplexType");
            serverComplexType.AddStructuralProperty("Number", EdmPrimitiveTypeKind.Int32);
            this.serverModel.AddElement(serverComplexType);
            var entityContainer = new EdmEntityContainer("Fake", "Container");
            this.serverModel.AddElement(entityContainer);
            entityContainer.AddEntitySet("Entities", serverEntityType);
            entityContainer.AddEntitySet("Parents", parentType);

            parentType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Navigation", Target = serverEntityType, TargetMultiplicity = EdmMultiplicity.Many });
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:19,代码来源:JsonLightTypeResolverTests.cs

示例10: BuildEntitySets

        private void BuildEntitySets(EdmEntityContainer container, IEnumerable<EntityElement> rootElements, TypeBuilder typeBuilder)
        {
            foreach (var rootEntity in rootElements)
            {
                var entitySetName = rootEntity.EntitySetName ?? rootEntity.ResolveName();
                var schemaType = typeBuilder.BuildSchemaType(rootEntity);

                container.AddEntitySet(entitySetName, (IEdmEntityType)schemaType);
            }
        }
开发者ID:2gis,项目名称:nuclear-river,代码行数:10,代码来源:EdmModelBuilder.cs

示例11: ODataJsonLightReaderIntegrationTests

 static ODataJsonLightReaderIntegrationTests()
 {
     EdmModel tmp = new EdmModel();
     EntityType = new EdmEntityType("Namespace", "EntityType");
     EdmEntityContainer edmEntityContainer = new EdmEntityContainer("Namespace", "Container_sub");
     EntitySet = edmEntityContainer.AddEntitySet("EntitySet", EntityType);
     tmp.AddElement(edmEntityContainer);
     tmp.Fixup();
     Model = TestUtils.WrapReferencedModelsToMainModel("Namespace", "Container", tmp);
 }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:10,代码来源:ODataJsonLightReaderIntegrationTests.cs

示例12: GetModelAsync

 public Task<IEdmModel> GetModelAsync(InvocationContext context, CancellationToken cancellationToken)
 {
     var model = new EdmModel();
     var dummyType = new EdmEntityType("NS", "Dummy");
     model.AddElement(dummyType);
     var container = new EdmEntityContainer("NS", "DefaultContainer");
     container.AddEntitySet("Test", dummyType);
     model.AddElement(container);
     return Task.FromResult((IEdmModel)model);
 }
开发者ID:kosinsky,项目名称:RESTier,代码行数:10,代码来源:Api.Tests.cs

示例13: ODataAtomWriterIntegrationTests

        static ODataAtomWriterIntegrationTests()
        {
            Model = new EdmModel();
            EntityType = new EdmEntityType("Namespace", "EntityType");

            Model.AddElement(EntityType);
            var entityContainer = new EdmEntityContainer("Namespace", "Container");
            EntitySet = entityContainer.AddEntitySet("EntitySet", EntityType);
            Model.AddElement(entityContainer);
            Model.Fixup();
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:11,代码来源:ODataAtomWriterIntegrationTests.cs

示例14: Initialize

 public void Initialize()
 {
     EdmModel tmp = new EdmModel();
     this.type = new EdmEntityType("Namespace", "Type");
     this.type.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Target = this.type, TargetMultiplicity = EdmMultiplicity.Many, Name = "NavProp" });
     this.type.AddProperty(new EdmStructuralProperty(this.type, "PrimitiveProp", EdmCoreModel.Instance.GetInt32(false)));
     tmp.AddElement(this.type);
     EdmEntityContainer edmEntityContainer = new EdmEntityContainer("Namespace", "Container_sub");
     this.entitySet = edmEntityContainer.AddEntitySet("EntitySet", this.type);
     tmp.AddElement(edmEntityContainer);
     this.model = TestUtils.WrapReferencedModelsToMainModel("Namespace", "Container", tmp);
 }
开发者ID:rossjempson,项目名称:odata.net,代码行数:12,代码来源:FeedAnnotationIntegrationTests.cs

示例15: CreateTestModel

        private IEdmModel CreateTestModel()
        {
            EdmModel model = new EdmModel();
            EdmEntityContainer defaultContainer = new EdmEntityContainer("TestModel", "Default");
            model.AddElement(defaultContainer);

            var productType = new EdmEntityType("TestModel", "Product");
            EdmStructuralProperty idProperty = new EdmStructuralProperty(productType, "Id", EdmCoreModel.Instance.GetInt32(false));
            productType.AddProperty(idProperty);
            productType.AddKeys(idProperty);
            productType.AddProperty(new EdmStructuralProperty(productType, "Name", EdmCoreModel.Instance.GetString(true)));
            model.AddElement(productType);

            var customerType = new EdmEntityType("TestModel", "Customer");
            idProperty = new EdmStructuralProperty(customerType, "Id", EdmCoreModel.Instance.GetInt32(false));
            customerType.AddProperty(idProperty);
            customerType.AddKeys(idProperty);
            customerType.AddProperty(new EdmStructuralProperty(customerType, "Name", EdmCoreModel.Instance.GetString(true)));
            model.AddElement(productType);

            defaultContainer.AddEntitySet("Products", productType);
            defaultContainer.AddEntitySet("Customers", customerType);
            defaultContainer.AddSingleton("SingleProduct", productType);
            defaultContainer.AddSingleton("SingleCustomer", customerType);

            EdmAction action = new EdmAction("TestModel", "SimpleAction", null/*returnType*/, false /*isBound*/, null /*entitySetPath*/);
            model.AddElement(action);
            defaultContainer.AddActionImport("SimpleActionImport", action);

            EdmFunction function1 = new EdmFunction("TestModel", "SimpleFunction1", EdmCoreModel.Instance.GetInt32(false), false /*isbound*/, null, true);
            function1.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false));
            defaultContainer.AddFunctionImport("SimpleFunctionImport1", function1);

            EdmFunction function2 = new EdmFunction("TestModel", "SimpleFunction2", EdmCoreModel.Instance.GetInt32(false), false /*isbound*/, null, true);
            function2.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false));
            defaultContainer.AddFunctionImport("SimpleFunctionImport2", function1, null, true /*IncludeInServiceDocument*/);

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


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