Beispiel #1
0
        private void RemoveFragment(
            EntitySet entitySet,
            EntityTypeMapping entityTypeMapping,
            MappingFragment fragment)
        {
            EdmProperty defaultDiscriminator = fragment.GetDefaultDiscriminator();

            if (defaultDiscriminator != null && entityTypeMapping.EntityType.BaseType != null && !entityTypeMapping.EntityType.Abstract)
            {
                ColumnMapping columnMapping = this._tableMappings[fragment.Table].ColumnMappings.SingleOrDefault <ColumnMapping>((Func <ColumnMapping, bool>)(cm => cm.Column == defaultDiscriminator));
                if (columnMapping != null)
                {
                    PropertyMappingSpecification mappingSpecification = columnMapping.PropertyMappings.SingleOrDefault <PropertyMappingSpecification>((Func <PropertyMappingSpecification, bool>)(pm => pm.EntityType == entityTypeMapping.EntityType));
                    if (mappingSpecification != null)
                    {
                        columnMapping.PropertyMappings.Remove(mappingSpecification);
                    }
                }
                defaultDiscriminator.Nullable = true;
            }
            if (entityTypeMapping.EntityType.Abstract)
            {
                foreach (ColumnMapping columnMapping in this._tableMappings[fragment.Table].ColumnMappings.Where <ColumnMapping>((Func <ColumnMapping, bool>)(cm => cm.PropertyMappings.All <PropertyMappingSpecification>((Func <PropertyMappingSpecification, bool>)(pm => pm.EntityType == entityTypeMapping.EntityType)))))
                {
                    fragment.Table.RemoveMember((EdmMember)columnMapping.Column);
                }
            }
            entityTypeMapping.RemoveFragment(fragment);
            if (entityTypeMapping.MappingFragments.Any <MappingFragment>())
            {
                return;
            }
            this._databaseMapping.GetEntitySetMapping(entitySet).RemoveTypeMapping(entityTypeMapping);
        }
Beispiel #2
0
        private void RemoveFragment(
            EntitySet entitySet, EntityTypeMapping entityTypeMapping, MappingFragment fragment)
        {
            // Make the default discriminator nullable if this type isn't using it but there is a base type
            var defaultDiscriminator = fragment.GetDefaultDiscriminator();

            if (defaultDiscriminator != null &&
                entityTypeMapping.EntityType.BaseType != null &&
                !entityTypeMapping.EntityType.Abstract)
            {
                var columnMapping =
                    _tableMappings[fragment.Table].ColumnMappings.SingleOrDefault(
                        cm => cm.Column == defaultDiscriminator);

                if (columnMapping != null)
                {
                    var propertyMapping = columnMapping.PropertyMappings.SingleOrDefault(
                        pm => pm.EntityType == entityTypeMapping.EntityType);
                    if (propertyMapping != null)
                    {
                        columnMapping.PropertyMappings.Remove(propertyMapping);
                    }
                }

                defaultDiscriminator.Nullable = true;
            }

            // The default TPH mapping may result in columns being created that are no longer required
            // when an abstract type mapping to the table is removed, for example in TPC cases. We need
            // to remove these columns.
            if (entityTypeMapping.EntityType.Abstract)
            {
                foreach (var columnMapping in _tableMappings[fragment.Table].ColumnMappings.Where(
                             cm => cm.PropertyMappings.All(pm => pm.EntityType == entityTypeMapping.EntityType)))
                {
                    fragment.Table.RemoveMember(columnMapping.Column);
                }
            }

            entityTypeMapping.RemoveFragment(fragment);

            if (!entityTypeMapping.MappingFragments.Any())
            {
                _databaseMapping.GetEntitySetMapping(entitySet).RemoveTypeMapping(entityTypeMapping);
            }
        }
Beispiel #3
0
        public static void RemoveDefaultDiscriminator(
            this MappingFragment entityTypeMappingFragment,
            EntitySetMapping entitySetMapping)
        {
            EdmProperty discriminatorColumn = entityTypeMappingFragment.RemoveDefaultDiscriminatorCondition();

            if (discriminatorColumn != null)
            {
                EntityType table = entityTypeMappingFragment.Table;
                table.Properties.Where <EdmProperty>((Func <EdmProperty, bool>)(c => c.Name.Equals(discriminatorColumn.Name, StringComparison.Ordinal))).ToList <EdmProperty>().Each <EdmProperty>(new Action <EdmProperty>(((StructuralType)table).RemoveMember));
            }
            if (entitySetMapping == null || !entityTypeMappingFragment.IsConditionOnlyFragment() || entityTypeMappingFragment.ColumnConditions.Any <ConditionPropertyMapping>())
            {
                return;
            }
            EntityTypeMapping typeMapping = entitySetMapping.EntityTypeMappings.Single <EntityTypeMapping>((Func <EntityTypeMapping, bool>)(etm => etm.MappingFragments.Contains(entityTypeMappingFragment)));

            typeMapping.RemoveFragment(entityTypeMappingFragment);
            if (typeMapping.MappingFragments.Count != 0)
            {
                return;
            }
            entitySetMapping.RemoveTypeMapping(typeMapping);
        }