private void ReconfigureEntityTypesAsComplexType(IEnumerable <IEntityTypeConfiguration> misconfiguredEntityTypes)
        {
            IEnumerable <IEntityTypeConfiguration> actualEntityTypes = StructuralTypes
                                                                       .Except(misconfiguredEntityTypes)
                                                                       .OfType <IEntityTypeConfiguration>()
                                                                       .ToArray();

            foreach (IEntityTypeConfiguration misconfiguredEntityType in misconfiguredEntityTypes)
            {
                RemoveStructuralType(misconfiguredEntityType.ClrType);

                IComplexTypeConfiguration newComplexType = AddComplexType(misconfiguredEntityType.ClrType);
                foreach (PropertyInfo ignoredProperty in misconfiguredEntityType.IgnoredProperties)
                {
                    newComplexType.RemoveProperty(ignoredProperty);
                }

                foreach (IEntityTypeConfiguration entityToBePatched in actualEntityTypes)
                {
                    NavigationPropertyConfiguration[] propertiesToBeRemoved = entityToBePatched
                                                                              .NavigationProperties
                                                                              .Where(navigationProperty => navigationProperty.RelatedClrType == misconfiguredEntityType.ClrType)
                                                                              .ToArray();
                    foreach (NavigationPropertyConfiguration propertyToBeRemoved in propertiesToBeRemoved)
                    {
                        entityToBePatched.RemoveProperty(propertyToBeRemoved.PropertyInfo);

                        if (propertyToBeRemoved.Multiplicity == EdmMultiplicity.Many)
                        {
                            entityToBePatched.AddCollectionProperty(propertyToBeRemoved.PropertyInfo);
                        }
                        else
                        {
                            entityToBePatched.AddComplexProperty(propertyToBeRemoved.PropertyInfo);
                        }
                    }
                }
            }
        }
Example #2
0
        private void ReconfigureEntityTypesAsComplexType(IEnumerable <IEntityTypeConfiguration> misconfiguredEntityTypes)
        {
            IEnumerable <IEntityTypeConfiguration> actualEntityTypes = StructuralTypes
                                                                       .Except(misconfiguredEntityTypes)
                                                                       .OfType <IEntityTypeConfiguration>()
                                                                       .ToArray();

            foreach (IEntityTypeConfiguration misconfiguredEntityType in misconfiguredEntityTypes)
            {
                RemoveStructuralType(misconfiguredEntityType.ClrType);

                IComplexTypeConfiguration newComplexType = AddComplexType(misconfiguredEntityType.ClrType);
                foreach (var ignoredProperty in misconfiguredEntityType.IgnoredProperties)
                {
                    newComplexType.RemoveProperty(ignoredProperty);
                }

                foreach (IEntityTypeConfiguration entityToBePatched in actualEntityTypes)
                {
                    NavigationPropertyConfiguration[] propertiesToBeRemoved = entityToBePatched
                                                                              .NavigationProperties
                                                                              .Where(navigationProperty => navigationProperty.RelatedClrType == misconfiguredEntityType.ClrType)
                                                                              .ToArray();
                    foreach (NavigationPropertyConfiguration propertyToBeRemoved in propertiesToBeRemoved)
                    {
                        if (propertyToBeRemoved.Multiplicity == EdmMultiplicity.Many)
                        {
                            // complex collections are not supported.
                            throw Error.NotSupported(SRResources.CollectionPropertiesNotSupported, propertyToBeRemoved.PropertyInfo.Name, propertyToBeRemoved.PropertyInfo.ReflectedType.FullName);
                        }
                        entityToBePatched.RemoveProperty(propertyToBeRemoved.PropertyInfo);
                        entityToBePatched.AddComplexProperty(propertyToBeRemoved.PropertyInfo);
                    }
                }

                AddComplexType(misconfiguredEntityType.ClrType);
            }
        }