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


C# EdmEntityType.AddNavigationProperty方法代码示例

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


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

示例1: AddNavigationProperty_should_create_and_add_navigation_property

        public void AddNavigationProperty_should_create_and_add_navigation_property()
        {
            var entityType = new EdmEntityType();
            var associationType = new EdmAssociationType();

            var navigationProperty = entityType.AddNavigationProperty("N", associationType);

            Assert.NotNull(navigationProperty);
            Assert.Equal("N", navigationProperty.Name);
            Assert.Same(associationType, navigationProperty.Association);
            Assert.True(entityType.NavigationProperties.Contains(navigationProperty));
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:12,代码来源:EdmEntityTypeExtensionsTests.cs

示例2: Map

        public void Map(
            PropertyInfo propertyInfo, EdmEntityType entityType, Func<EntityTypeConfiguration> entityTypeConfiguration)
        {
            Contract.Requires(propertyInfo != null);
            Contract.Requires(entityType != null);
            Contract.Requires(entityTypeConfiguration != null);

            var targetType = propertyInfo.PropertyType;
            var targetAssociationEndKind = EdmAssociationEndKind.Optional;

            if (targetType.IsCollection(out targetType))
            {
                targetAssociationEndKind = EdmAssociationEndKind.Many;
            }

            var targetEntityType = _typeMapper.MapEntityType(targetType);

            if (targetEntityType != null)
            {
                var sourceAssociationEndKind
                    = targetAssociationEndKind.IsMany()
                          ? EdmAssociationEndKind.Optional
                          : EdmAssociationEndKind.Many;

                var associationType = _typeMapper.MappingContext.Model.AddAssociationType(
                    entityType.Name + "_" + propertyInfo.Name,
                    entityType,
                    sourceAssociationEndKind,
                    targetEntityType,
                    targetAssociationEndKind);

                _typeMapper.MappingContext.Model.AddAssociationSet(associationType.Name, associationType);

                var navigationProperty
                    = entityType.AddNavigationProperty(propertyInfo.Name, associationType);

                navigationProperty.SetClrPropertyInfo(propertyInfo);

                _typeMapper.MappingContext.ConventionsConfiguration.ApplyPropertyConfiguration(
                    propertyInfo,
                    () => entityTypeConfiguration().Navigation(propertyInfo));

                new AttributeMapper(_typeMapper.MappingContext.AttributeProvider)
                    .Map(propertyInfo, navigationProperty.Annotations);
            }
        }
开发者ID:junxy,项目名称:entityframework,代码行数:46,代码来源:NavigationPropertyMapper.cs

示例3: CreateModelFixture

        private static EdmModel CreateModelFixture(
            out EdmEntityType declaringEntityType, out EdmEntityType complexEntityType)
        {
            var model = new EdmModel().Initialize();

            declaringEntityType = model.AddEntityType("E");
            complexEntityType = model.AddEntityType("C");
            complexEntityType.AddPrimitiveProperty("P");

            var associationType
                = model.AddAssociationType(
                    "A",
                    declaringEntityType, EdmAssociationEndKind.Many,
                    complexEntityType, EdmAssociationEndKind.Optional);

            declaringEntityType.AddNavigationProperty("E.C", associationType);

            return model;
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:19,代码来源:ComplexTypeDiscoveryConventionTests.cs

示例4: GetNavigationProperty_should_return_correct_property

        public void GetNavigationProperty_should_return_correct_property()
        {
            var entityType = new EdmEntityType();
            var associationType = new EdmAssociationType().Initialize();
            var property = entityType.AddNavigationProperty("Foo", associationType);

            var foundProperty = entityType.GetNavigationProperty("Foo");

            Assert.NotNull(foundProperty);
            Assert.Same(property, foundProperty);
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:11,代码来源:EdmEntityTypeExtensionsTests.cs


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