private void Transform() { foreach (EntitySet entitySet1 in this._entityTypes.GetEntitySets()) { EntitySet entitySet = entitySet1; Dictionary <TableMapping, Dictionary <EntityType, EntityTypeMapping> > dictionary = new Dictionary <TableMapping, Dictionary <EntityType, EntityTypeMapping> >(); foreach (EntityType entityType1 in this._entityTypes.GetEntityTypes(entitySet)) { EntityType entityType = entityType1; foreach (TableMapping tableMapping in this._tableMappings.Values.Where <TableMapping>((Func <TableMapping, bool>)(tm => tm.EntityTypes.Contains(entitySet, entityType)))) { Dictionary <EntityType, EntityTypeMapping> rootMappings; if (!dictionary.TryGetValue(tableMapping, out rootMappings)) { rootMappings = new Dictionary <EntityType, EntityTypeMapping>(); dictionary.Add(tableMapping, rootMappings); } EntityMappingService.RemoveRedundantDefaultDiscriminators(tableMapping); bool requiresIsTypeOf = this.DetermineRequiresIsTypeOf(tableMapping, entitySet, entityType); EntityTypeMapping propertiesTypeMapping; MappingFragment propertiesTypeMappingFragment; if (this.FindPropertyEntityTypeMapping(tableMapping, entitySet, entityType, requiresIsTypeOf, out propertiesTypeMapping, out propertiesTypeMappingFragment)) { bool entityTypeMapping1 = EntityMappingService.DetermineRequiresSplitEntityTypeMapping(tableMapping, entityType, requiresIsTypeOf); EntityTypeMapping conditionTypeMapping = this.FindConditionTypeMapping(entityType, entityTypeMapping1, propertiesTypeMapping); MappingFragment typeMappingFragment = EntityMappingService.FindConditionTypeMappingFragment(this._databaseMapping.Database.GetEntitySet(tableMapping.Table), propertiesTypeMappingFragment, conditionTypeMapping); if (requiresIsTypeOf) { if (!propertiesTypeMapping.IsHierarchyMapping) { EntityTypeMapping entityTypeMapping2 = this._databaseMapping.GetEntityTypeMappings(entityType).SingleOrDefault <EntityTypeMapping>((Func <EntityTypeMapping, bool>)(etm => etm.IsHierarchyMapping)); if (entityTypeMapping2 == null) { if (propertiesTypeMapping.MappingFragments.Count > 1) { EntityTypeMapping typeMapping = propertiesTypeMapping.Clone(); this._databaseMapping.GetEntitySetMappings().Single <EntitySetMapping>((Func <EntitySetMapping, bool>)(esm => esm.EntityTypeMappings.Contains(propertiesTypeMapping))).AddTypeMapping(typeMapping); foreach (MappingFragment fragment in propertiesTypeMapping.MappingFragments.Where <MappingFragment>((Func <MappingFragment, bool>)(tmf => tmf != propertiesTypeMappingFragment)).ToArray <MappingFragment>()) { propertiesTypeMapping.RemoveFragment(fragment); typeMapping.AddFragment(fragment); } } propertiesTypeMapping.AddIsOfType(propertiesTypeMapping.EntityType); } else { propertiesTypeMapping.RemoveFragment(propertiesTypeMappingFragment); if (propertiesTypeMapping.MappingFragments.Count == 0) { this._databaseMapping.GetEntitySetMapping(entitySet).RemoveTypeMapping(propertiesTypeMapping); } propertiesTypeMapping = entityTypeMapping2; propertiesTypeMapping.AddFragment(propertiesTypeMappingFragment); } } rootMappings.Add(entityType, propertiesTypeMapping); } EntityMappingService.ConfigureTypeMappings(tableMapping, rootMappings, entityType, propertiesTypeMappingFragment, typeMappingFragment); if (propertiesTypeMappingFragment.IsUnmappedPropertiesFragment() && propertiesTypeMappingFragment.ColumnMappings.All <ColumnMappingBuilder>((Func <ColumnMappingBuilder, bool>)(pm => entityType.GetKeyProperties().Contains(pm.PropertyPath.First <EdmProperty>())))) { this.RemoveFragment(entitySet, propertiesTypeMapping, propertiesTypeMappingFragment); if (entityTypeMapping1 && typeMappingFragment.ColumnMappings.All <ColumnMappingBuilder>((Func <ColumnMappingBuilder, bool>)(pm => entityType.GetKeyProperties().Contains(pm.PropertyPath.First <EdmProperty>())))) { this.RemoveFragment(entitySet, conditionTypeMapping, typeMappingFragment); } } EntityMappingConfiguration.CleanupUnmappedArtifacts(this._databaseMapping, tableMapping.Table); foreach (ForeignKeyBuilder foreignKeyBuilder in tableMapping.Table.ForeignKeyBuilders) { AssociationType associationType = foreignKeyBuilder.GetAssociationType(); if (associationType != null && associationType.IsRequiredToNonRequired()) { AssociationEndMember principalEnd; AssociationEndMember dependentEnd; foreignKeyBuilder.GetAssociationType().TryGuessPrincipalAndDependentEnds(out principalEnd, out dependentEnd); if (dependentEnd.GetEntityType() == entityType) { this.MarkColumnsAsNonNullableIfNoTableSharing(entitySet, tableMapping.Table, entityType, foreignKeyBuilder.DependentColumns); } } } } } } this.ConfigureAssociationSetMappingForeignKeys(entitySet); } }