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


C# EdmModel.RemoveEntityType方法代码示例

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


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

示例1: RemoveEntityType_should_remove_type_and_set

        public void RemoveEntityType_should_remove_type_and_set()
        {
            var model = new EdmModel().Initialize();
            var entityType = model.AddEntityType("Foo");
            model.AddEntitySet("FooSet", entityType);

            model.RemoveEntityType(entityType);

            Assert.Equal(0, model.GetEntityTypes().Count());
            Assert.Equal(0, model.Containers.First().EntitySets.Count());
        }
开发者ID:junxy,项目名称:entityframework,代码行数:11,代码来源:EdmModelExtensionsTests.cs

示例2: where

        void IEdmConvention.Apply(EdmModel model)
        {
            // Query the model for candidate complex types.
            //   - The rules for complex type discovery are as follows:
            //      1) The entity does not have a key or base type.
            //      2) The entity does not have explicit configuration or has only structural type configuration.
            //      3) The entity does not have any outbound navigation properties.
            //         The entity only has inbound associations where:
            //          4) The association does not have a constraint defined.
            //          5) The association does not have explicit configuration.
            //          6) The association is not self-referencing.
            //          7) The other end of the association is Optional.
            //      8) Any inbound navigation properties do not have explicit configuration.

            var candidates
                = from entityType in model.GetEntityTypes()
                  where entityType.DeclaredKeyProperties.Count == 0 // (1)
                        && entityType.BaseType == null
                  // (1)
                  let entityTypeConfiguration = entityType.GetConfiguration() as EntityTypeConfiguration
                  where ((entityTypeConfiguration == null) // (2)
                         || (!entityTypeConfiguration.IsExplicitEntity
                             && entityTypeConfiguration.IsStructuralConfigurationOnly)) // (2)
                        && !entityType.NavigationProperties.Any()
                  // (3)
                  let matchingAssociations
                      = from associationType in model.GetAssociationTypes()
                        where associationType.SourceEnd.EntityType == entityType ||
                              associationType.TargetEnd.EntityType == entityType
                        let declaringEnd
                            = associationType.SourceEnd.EntityType == entityType
                                  ? associationType.SourceEnd
                                  : associationType.TargetEnd
                        let declaringEntity
                            = associationType.GetOtherEnd(declaringEnd).EntityType
                        let navigationProperties
                            = declaringEntity.NavigationProperties
                            .Where(n => n.ResultEnd.EntityType == entityType)
                        select new
                            {
                                DeclaringEnd = declaringEnd,
                                AssociationType = associationType,
                                DeclaringEntityType = declaringEntity,
                                NavigationProperties = navigationProperties.ToList()
                            }
                  where matchingAssociations.All(
                      a => a.AssociationType.Constraint == null // (4)
                           && a.AssociationType.GetConfiguration() == null // (5)
                           && !a.AssociationType.IsSelfReferencing() // (6)
                           && a.DeclaringEnd.IsOptional() // (7)
                           && a.NavigationProperties.All(n => n.GetConfiguration() == null))
                  // (8)
                  select new
                      {
                          EntityType = entityType,
                          MatchingAssociations = matchingAssociations.ToList(),
                      };

            // Transform candidate entities into complex types
            foreach (var candidate in candidates.ToList())
            {
                var complexType = model.AddComplexType(candidate.EntityType.Name);

                foreach (var property in candidate.EntityType.DeclaredProperties)
                {
                    complexType.DeclaredProperties.Add(property);
                }

                foreach (var annotation in candidate.EntityType.Annotations)
                {
                    complexType.Annotations.Add(annotation);
                }

                foreach (var association in candidate.MatchingAssociations)
                {
                    foreach (var navigationProperty in association.NavigationProperties)
                    {
                        if (association.DeclaringEntityType.NavigationProperties.Contains(navigationProperty))
                        {
                            association.DeclaringEntityType.DeclaredNavigationProperties.Remove(navigationProperty);
                            var complexProperty =
                                association.DeclaringEntityType.AddComplexProperty(navigationProperty.Name, complexType);
                            foreach (var annotation in navigationProperty.Annotations)
                            {
                                complexProperty.Annotations.Add(annotation);
                            }
                        }
                    }

                    model.RemoveAssociationType(association.AssociationType);
                }

                model.RemoveEntityType(candidate.EntityType);
            }
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:95,代码来源:ComplexTypeDiscoveryConvention.cs


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