• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Edm.EdmModel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Data.Entity.Core.Metadata.Edm.EdmModel的典型用法代码示例。如果您正苦于以下问题:C# EdmModel类的具体用法?C# EdmModel怎么用?C# EdmModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



EdmModel类属于System.Data.Entity.Core.Metadata.Edm命名空间,在下文中一共展示了EdmModel类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: SimpleMappingContext

        public SimpleMappingContext(EdmModel storeModel, bool includeForeignKeyProperties)
        {
            Debug.Assert(storeModel != null, "storeModel != null");

            StoreModel = storeModel;
            IncludeForeignKeyProperties = includeForeignKeyProperties;
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:7,代码来源:SimpleMappingContext.cs


示例2: Generate_can_map_a_simple_entity_type_and_set

        public void Generate_can_map_a_simple_entity_type_and_set()
        {
            var model = new EdmModel(DataSpace.CSpace);
            var entityType = model.AddEntityType("E");
            var type = typeof(object);

            entityType.GetMetadataProperties().SetClrType(type);
            var property = EdmProperty.CreatePrimitive("P1", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType.AddMember(property);
            var property1 = EdmProperty.CreatePrimitive("P2", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType.AddMember(property1);
            var entitySet = model.AddEntitySet("ESet", entityType);

            var databaseMapping = CreateDatabaseMappingGenerator().Generate(model);

            var entitySetMapping = databaseMapping.GetEntitySetMapping(entitySet);

            Assert.NotNull(entitySetMapping);
            Assert.Same(entitySet, entitySetMapping.EntitySet);

            var entityTypeMapping = entitySetMapping.EntityTypeMappings.Single();

            Assert.Same(entityType, entityTypeMapping.EntityType);
            Assert.NotNull(entityTypeMapping.MappingFragments.Single().Table);
            Assert.Equal("E", entityTypeMapping.MappingFragments.Single().Table.Name);
            Assert.Equal(2, entityTypeMapping.MappingFragments.Single().Table.Properties.Count);
            Assert.Equal(typeof(object), entityTypeMapping.GetClrType());
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:30,代码来源:DatabaseMappingGeneratorTests.cs


示例3: EdmModelValidationContext

        public EdmModelValidationContext(EdmModel model, bool validateSyntax)
        {
            DebugCheck.NotNull(model);

            _model = model;
            _validateSyntax = validateSyntax;
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:7,代码来源:EdmModelValidationContext.cs


示例4: Configure_should_configure_modification_functions

        public void Configure_should_configure_modification_functions()
        {
            var model = new EdmModel(DataSpace.CSpace);

            var entityType = model.AddEntityType("E");
            entityType.GetMetadataProperties().SetClrType(typeof(object));

            model.AddEntitySet("ESet", entityType);

            var modificationFunctionsConfigurationMock = new Mock<ModificationStoredProceduresConfiguration>();

            var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object));
            entityTypeConfiguration.MapToStoredProcedures(modificationFunctionsConfigurationMock.Object, true);

            entityType.SetConfiguration(entityTypeConfiguration);

            var databaseMapping
                = new DatabaseMappingGenerator(ProviderRegistry.Sql2008_ProviderInfo, ProviderRegistry.Sql2008_ProviderManifest).Generate(model);

            entityTypeConfiguration.Configure(entityType, databaseMapping, ProviderRegistry.Sql2008_ProviderManifest);

            modificationFunctionsConfigurationMock
                .Verify(
                    m => m.Configure(
                        It.IsAny<EntityTypeModificationFunctionMapping>(), It.IsAny<DbProviderManifest>()),
                    Times.Once());
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:27,代码来源:EntityTypeConfigurationTests.cs


示例5: Can_set_owner_and_corresponding_association_added_to_model

        public void Can_set_owner_and_corresponding_association_added_to_model()
        {
            var database = new EdmModel(DataSpace.SSpace);

            var foreignKeyBuilder = new ForeignKeyBuilder(database, "FK");

            var principalTable = database.AddTable("P");

            foreignKeyBuilder.PrincipalTable = principalTable;

            var dependentTable = database.AddTable("D");

            foreignKeyBuilder.SetOwner(dependentTable);

            var associationType = database.GetAssociationType("FK");

            Assert.NotNull(associationType);
            Assert.NotNull(associationType.SourceEnd);
            Assert.NotNull(associationType.TargetEnd);
            Assert.Same(principalTable, associationType.SourceEnd.GetEntityType());
            Assert.Equal("P", associationType.SourceEnd.Name);
            Assert.Same(dependentTable, associationType.TargetEnd.GetEntityType());
            Assert.Equal("D", associationType.TargetEnd.Name);

            var associationSet = database.GetAssociationSet(associationType);

            Assert.NotNull(associationSet);
            Assert.NotNull(associationSet.SourceSet);
            Assert.NotNull(associationSet.TargetSet);
            
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:31,代码来源:ForeignKeyBuilderTests.cs


示例6: Apply_should_not_match_key_that_is_also_an_fk

        public void Apply_should_not_match_key_that_is_also_an_fk()
        {
            var model = new EdmModel(DataSpace.CSpace);
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int64));

            entityType.AddKeyMember(property);

            var associationType
                = model.AddAssociationType(
                    "A", new EntityType("E", "N", DataSpace.CSpace), RelationshipMultiplicity.ZeroOrOne,
                    entityType, RelationshipMultiplicity.Many);

            associationType.Constraint
                = new ReferentialConstraint(
                    associationType.SourceEnd,
                    associationType.TargetEnd,
                    new[] { property },
                    new[] { property });

            (new StoreGeneratedIdentityKeyConvention())
                .Apply(entityType, new DbModel(model, null));

            Assert.Null(entityType.KeyProperties.Single().GetStoreGeneratedPattern());
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:25,代码来源:StoreGeneratedIdentityKeyConventionTests.cs


示例7: HasCascadeDeletePath_should_return_true_for_transitive_cascade

        public void HasCascadeDeletePath_should_return_true_for_transitive_cascade()
        {
            var model = new EdmModel(DataSpace.CSpace);
            var entityTypeA = model.AddEntityType("A");
            var entityTypeB = model.AddEntityType("B");
            var entityTypeC = model.AddEntityType("B");
            var associationTypeA
                = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)
                      {
                          SourceEnd = new AssociationEndMember("S", entityTypeA),
                          TargetEnd = new AssociationEndMember("T", entityTypeB)
                      };

            associationTypeA.SourceEnd.DeleteBehavior = OperationAction.Cascade;
            model.AddAssociationType(associationTypeA);
            var associationTypeB
                = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)
                      {
                          SourceEnd = new AssociationEndMember("S", entityTypeB),
                          TargetEnd = new AssociationEndMember("T", entityTypeC)
                      };

            associationTypeB.SourceEnd.DeleteBehavior = OperationAction.Cascade;
            model.AddAssociationType(associationTypeB);

            Assert.True(model.HasCascadeDeletePath(entityTypeA, entityTypeB));
            Assert.True(model.HasCascadeDeletePath(entityTypeB, entityTypeC));
            Assert.True(model.HasCascadeDeletePath(entityTypeA, entityTypeC));
            Assert.False(model.HasCascadeDeletePath(entityTypeB, entityTypeA));
            Assert.False(model.HasCascadeDeletePath(entityTypeC, entityTypeB));
            Assert.False(model.HasCascadeDeletePath(entityTypeC, entityTypeA));
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:32,代码来源:EdmModelExtensionsTests.cs


示例8: Configure_should_uniquify_unconfigured_assocation_function_names

        public void Configure_should_uniquify_unconfigured_assocation_function_names()
        {
            var typeA = new MockType("A");
            var typeB = new MockType("B").Property(typeA.AsCollection(), "As");
            var mockPropertyInfo = typeB.GetProperty("As");
            typeA.Property(typeB.AsCollection(), "Bs");

            var modelConfiguration = new ModelConfiguration();

            var navigationPropertyConfiguration
                = modelConfiguration.Entity(typeB).Navigation(mockPropertyInfo);

            navigationPropertyConfiguration.ModificationFunctionsConfiguration
                = new ModificationFunctionsConfiguration();

            var modificationFunctionConfiguration = new ModificationFunctionConfiguration();
            modificationFunctionConfiguration.HasName("M2M_Delete");

            navigationPropertyConfiguration.ModificationFunctionsConfiguration
                .Insert(modificationFunctionConfiguration);

            var model = new EdmModel(DataSpace.CSpace);

            var entityA = model.AddEntityType("A");
            entityA.Annotations.SetClrType(typeA);
            entityA.SetConfiguration(modelConfiguration.Entity(typeA));

            var entityB = model.AddEntityType("B");
            entityB.Annotations.SetClrType(typeB);
            entityB.SetConfiguration(modelConfiguration.Entity(typeB));

            model.AddEntitySet("AS", entityA);
            model.AddEntitySet("BS", entityB);

            var associationType
                = model.AddAssociationType(
                    "M2M",
                    entityA,
                    RelationshipMultiplicity.Many,
                    entityB,
                    RelationshipMultiplicity.Many);

            associationType.SetConfiguration(navigationPropertyConfiguration);

            var navigationProperty
                = entityB.AddNavigationProperty("As", associationType);

            navigationProperty.SetClrPropertyInfo(mockPropertyInfo);

            model.AddAssociationSet("M2MSet", associationType);

            var databaseMapping
                = new DatabaseMappingGenerator(ProviderRegistry.Sql2008_ProviderManifest)
                    .Generate(model);

            modelConfiguration.Configure(databaseMapping, ProviderRegistry.Sql2008_ProviderManifest);

            Assert.True(databaseMapping.Database.Functions.Any(f => f.Name == "M2M_Delete"));
            Assert.True(databaseMapping.Database.Functions.Any(f => f.Name == "M2M_Delete1"));
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:60,代码来源:ModelConfigurationTests.cs


示例9: Generate_can_map_a_simple_entity_type_and_set

        public void Generate_can_map_a_simple_entity_type_and_set()
        {
            var model = new EdmModel().Initialize();
            var entityType = model.AddEntityType("E");
            var type = typeof(object);

            entityType.Annotations.SetClrType(type);
            var property = EdmProperty.Primitive("P1", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType.AddMember(property);
            var property1 = EdmProperty.Primitive("P2", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType.AddMember(property1);
            var entitySet = model.AddEntitySet("ESet", entityType);

            var databaseMapping = new DatabaseMappingGenerator(ProviderRegistry.Sql2008_ProviderManifest).Generate(model);

            var entitySetMapping = databaseMapping.GetEntitySetMapping(entitySet);

            Assert.NotNull(entitySetMapping);
            Assert.Same(entitySet, entitySetMapping.EntitySet);

            var entityTypeMapping = entitySetMapping.EntityTypeMappings.Single();

            Assert.Same(entityType, entityTypeMapping.EntityType);
            Assert.NotNull(entityTypeMapping.MappingFragments.Single().Table);
            Assert.Equal("E", entityTypeMapping.MappingFragments.Single().Table.Name);
            Assert.Equal(2, entityTypeMapping.MappingFragments.Single().Table.Properties.Count);
            Assert.Equal(typeof(object), entityTypeMapping.GetClrType());
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:30,代码来源:DatabaseMappingGeneratorTests.cs


示例10: Configure_should_configure_inverse

        public void Configure_should_configure_inverse()
        {
            var inverseMockPropertyInfo = new MockPropertyInfo();
            var navigationPropertyConfiguration = new NavigationPropertyConfiguration(new MockPropertyInfo())
                                                      {
                                                          InverseNavigationProperty = inverseMockPropertyInfo
                                                      };
            var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);
            associationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
            associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace));
            var inverseAssociationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);
            inverseAssociationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
            inverseAssociationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace));
            var model = new EdmModel(DataSpace.CSpace);
            model.AddAssociationType(inverseAssociationType);
            var inverseNavigationProperty
                = model.AddEntityType("T")
                       .AddNavigationProperty("N", inverseAssociationType);
            inverseNavigationProperty.SetClrPropertyInfo(inverseMockPropertyInfo);

            navigationPropertyConfiguration.Configure(
                new NavigationProperty("N", TypeUsage.Create(associationType.TargetEnd.GetEntityType()))
                    {
                        RelationshipType = associationType
                    }, model, new EntityTypeConfiguration(typeof(object)));

            Assert.Same(associationType, inverseNavigationProperty.Association);
            Assert.Same(associationType.SourceEnd, inverseNavigationProperty.ResultEnd);
            Assert.Same(associationType.TargetEnd, inverseNavigationProperty.FromEndMember);
            Assert.Equal(0, model.AssociationTypes.Count());
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:31,代码来源:NavigationPropertyConfigurationTests.cs


示例11: Configure_should_rename_columns_when_right_keys_configured

        public void Configure_should_rename_columns_when_right_keys_configured()
        {
            var database = new EdmModel(DataSpace.CSpace);

            var associationSetMapping
                = new StorageAssociationSetMapping(
                    new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)),
                    new EntitySet())
                    .Initialize();

            var column = new EdmProperty("C");

            associationSetMapping.TargetEndMapping.AddProperty(new StorageScalarPropertyMapping(new EdmProperty("PK"), column));

            var manyToManyAssociationMappingConfiguration
                = new ManyToManyAssociationMappingConfiguration();

            manyToManyAssociationMappingConfiguration.MapRightKey("NewName");

            var mockPropertyInfo = new MockPropertyInfo();

            associationSetMapping.SourceEndMapping.EndMember = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
            associationSetMapping.SourceEndMapping.EndMember.SetClrPropertyInfo(mockPropertyInfo);

            manyToManyAssociationMappingConfiguration.Configure(associationSetMapping, database, mockPropertyInfo);

            Assert.Equal("NewName", column.Name);
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:28,代码来源:ManyToManyAssociationMappingConfigurationTests.cs


示例12: Configure_should_rename_table_when_table_configured

        public void Configure_should_rename_table_when_table_configured()
        {
            var database = new EdmModel(DataSpace.SSpace);
            var table = database.AddTable("OriginalName");

            var associationSetMapping
                = new StorageAssociationSetMapping(
                    new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)),
                    database.GetEntitySet(table))
                    .Initialize();

            var manyToManyAssociationMappingConfiguration
                = new ManyToManyAssociationMappingConfiguration();

            manyToManyAssociationMappingConfiguration.ToTable("NewName");

            var mockPropertyInfo = new MockPropertyInfo();

            associationSetMapping.SourceEndMapping.EndMember = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
            associationSetMapping.SourceEndMapping.EndMember.SetClrPropertyInfo(mockPropertyInfo);

            manyToManyAssociationMappingConfiguration.Configure(associationSetMapping, database, mockPropertyInfo);

            Assert.Equal("NewName", table.GetTableName().Name);
            Assert.Same(manyToManyAssociationMappingConfiguration, table.GetConfiguration());
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:26,代码来源:ManyToManyAssociationMappingConfigurationTests.cs


示例13: Map_should_create_association_sets_for_associations

        public void Map_should_create_association_sets_for_associations()
        {
            var modelConfiguration = new ModelConfiguration();
            var model = new EdmModel().Initialize();
            var entityType = new EntityType
                                 {
                                     Name = "Source"
                                 };
            model.AddEntitySet("Source", entityType);

            var mappingContext = new MappingContext(modelConfiguration, new ConventionsConfiguration(), model);

            new NavigationPropertyMapper(new TypeMapper(mappingContext))
                .Map(
                    new MockPropertyInfo(new MockType("Target"), "Nav"), entityType,
                    () => new EntityTypeConfiguration(typeof(object)));

            Assert.Equal(1, model.Containers.Single().AssociationSets.Count);

            var associationSet = model.Containers.Single().AssociationSets.Single();

            Assert.NotNull(associationSet);
            Assert.NotNull(associationSet.ElementType);
            Assert.Equal("Source_Nav", associationSet.Name);
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:25,代码来源:NavigationPropertyMapperTests.cs


示例14: GenerateModel_genertes_model_and_sets_all_the_properties

        public void GenerateModel_genertes_model_and_sets_all_the_properties()
        {
            var mockModelGenerator = new Mock<ModelGenerator>(new ModelBuilderSettings(), "storeNamespace");

            var storeModel = new EdmModel(DataSpace.SSpace);
            var mappingContext = new SimpleMappingContext(storeModel, true);
            mappingContext.AddMapping(
                storeModel.Containers.Single(),
                EntityContainer.Create("C", DataSpace.CSpace, null, null, null));

            mockModelGenerator
                .Setup(g => g.CreateStoreModel())
                .Returns(() => storeModel);
            mockModelGenerator
                .Setup(g => g.CreateMappingContext(It.Is<EdmModel>(model => model == storeModel)))
                .Returns(() => mappingContext);

            var errors = new List<EdmSchemaError>();
            var databaseMapping = mockModelGenerator.Object.GenerateModel(errors).DatabaseMapping;
            Assert.Same(storeModel, databaseMapping.Database);
            Assert.NotNull(databaseMapping.Model);
            Assert.Equal(1, databaseMapping.EntityContainerMappings.Count);
            mockModelGenerator.Verify(
                g => g.CreateMappingContext(It.IsAny<EdmModel>()), Times.Once());
            Assert.Empty(errors);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:26,代码来源:ModelGeneratorTests.cs


示例15: Store_model_initialized

 public void Store_model_initialized()
 {
     var storeModel = new EdmModel(DataSpace.SSpace);
     var mappingContext = new SimpleMappingContext(storeModel, true);
     Assert.Same(storeModel, mappingContext.StoreModel);
     Assert.True(mappingContext.IncludeForeignKeyProperties);
 }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:7,代码来源:SimpleMappingContextTests.cs


示例16: Serialize

        /// <summary>
        ///     Serialize the <see cref="EdmModel" /> to the XmlWriter.
        /// </summary>
        /// <param name="model">
        ///     The EdmModel to serialize, mut have only one <see cref="EdmNamespace" /> and one
        ///     <see
        ///         cref="Core.Metadata.Edm.EntityContainer" />
        /// </param>
        /// <param name="xmlWriter"> The XmlWriter to serialize to </param>
        public bool Serialize(EdmModel model, XmlWriter xmlWriter)
        {
            Check.NotNull(model, "model");
            Check.NotNull(xmlWriter, "xmlWriter");

            if (model.Namespaces.Count != 1
                || model.Containers.Count != 1)
            {
                Validator_OnError(
                    this,
                    new DataModelErrorEventArgs
                        {
                            ErrorMessage = Strings.Serializer_OneNamespaceAndOneContainer,
                        });
            }

            // validate the model first
            var validator = new DataModelValidator();
            validator.OnError += Validator_OnError;
            validator.Validate(model, true);

            if (_isModelValid)
            {
                var visitor = new EdmSerializationVisitor(xmlWriter, model.Version);
                visitor.Visit(model);
            }
            return _isModelValid;
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:37,代码来源:CsdlSerializer.cs


示例17: GlobalItems_should_return_namespace_items_and_containers

        public void GlobalItems_should_return_namespace_items_and_containers()
        {
            var model = new EdmModel(DataSpace.SSpace);

            model.AddItem(new EntityType("Entity", "Model", DataSpace.SSpace));

            Assert.Equal(2, model.GlobalItems.Count());
        }
开发者ID:,项目名称:,代码行数:8,代码来源:


示例18: Name_should_return_association_type_name

        public void Name_should_return_association_type_name()
        {
            var database = new EdmModel(DataSpace.SSpace);

            var foreignKeyBuilder = new ForeignKeyBuilder(database, "FK");

            Assert.Equal("FK", foreignKeyBuilder.Name);
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:8,代码来源:ForeignKeyBuilderTests.cs


示例19: Visit

        internal void Visit(EdmModel model)
        {
            DebugCheck.NotNull(model);

            EvaluateItem(model);

            VisitEdmModel(model);
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:8,代码来源:EdmModelValidationVisitor.cs


示例20: Validate_should_throw_on_error

        public void Validate_should_throw_on_error()
        {
            var model = new EdmModel(DataSpace.CSpace);

            model.AddItem(new EntityType("E", "N", DataSpace.CSpace));

            Assert.Throws<ModelValidationException>(() => model.Validate());
        }
开发者ID:,项目名称:,代码行数:8,代码来源:



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Edm.EdmProperty类代码示例发布时间:2022-05-26
下一篇:
C# Edm.EdmMember类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap