예제 #1
0
 private static bool DetermineRequiresSplitEntityTypeMapping(
     TableMapping tableMapping,
     EntityType entityType,
     bool requiresIsTypeOf)
 {
     if (requiresIsTypeOf)
     {
         return(EntityMappingService.HasConditions(tableMapping, entityType));
     }
     return(false);
 }
예제 #2
0
 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);
     }
 }
예제 #3
0
        private static void ConfigureTypeMappings(
            TableMapping tableMapping,
            Dictionary <EntityType, EntityTypeMapping> rootMappings,
            EntityType entityType,
            MappingFragment propertiesTypeMappingFragment,
            MappingFragment conditionTypeMappingFragment)
        {
            List <ColumnMappingBuilder>     columnMappingBuilderList     = new List <ColumnMappingBuilder>(propertiesTypeMappingFragment.ColumnMappings.Where <ColumnMappingBuilder>((Func <ColumnMappingBuilder, bool>)(pm => !pm.ColumnProperty.IsPrimaryKeyColumn)));
            List <ConditionPropertyMapping> conditionPropertyMappingList = new List <ConditionPropertyMapping>(propertiesTypeMappingFragment.ColumnConditions);

            foreach (var data in tableMapping.ColumnMappings.SelectMany((Func <ColumnMapping, IEnumerable <PropertyMappingSpecification> >)(cm => (IEnumerable <PropertyMappingSpecification>)cm.PropertyMappings), (cm, pm) => new
            {
                cm = cm,
                pm = pm
            }).Where(_param1 => _param1.pm.EntityType == entityType).Select(_param0 => new
            {
                Column = _param0.cm.Column,
                Property = _param0.pm
            }))
            {
                var columnMapping = data;
                if (columnMapping.Property.PropertyPath != null && !EntityMappingService.IsRootTypeMapping(rootMappings, columnMapping.Property.EntityType, columnMapping.Property.PropertyPath))
                {
                    ColumnMappingBuilder columnMappingBuilder1 = propertiesTypeMappingFragment.ColumnMappings.SingleOrDefault <ColumnMappingBuilder>((Func <ColumnMappingBuilder, bool>)(x => x.PropertyPath == columnMapping.Property.PropertyPath));
                    if (columnMappingBuilder1 != null)
                    {
                        columnMappingBuilderList.Remove(columnMappingBuilder1);
                    }
                    else
                    {
                        ColumnMappingBuilder columnMappingBuilder2 = new ColumnMappingBuilder(columnMapping.Column, columnMapping.Property.PropertyPath);
                        propertiesTypeMappingFragment.AddColumnMapping(columnMappingBuilder2);
                    }
                }
                if (columnMapping.Property.Conditions != null)
                {
                    foreach (ConditionPropertyMapping condition in (IEnumerable <ConditionPropertyMapping>)columnMapping.Property.Conditions)
                    {
                        if (conditionTypeMappingFragment.ColumnConditions.Contains <ConditionPropertyMapping>(condition))
                        {
                            conditionPropertyMappingList.Remove(condition);
                        }
                        else if (!entityType.Abstract)
                        {
                            conditionTypeMappingFragment.AddConditionProperty(condition);
                        }
                    }
                }
            }
            foreach (ColumnMappingBuilder columnMappingBuilder in columnMappingBuilderList)
            {
                propertiesTypeMappingFragment.RemoveColumnMapping(columnMappingBuilder);
            }
            foreach (ConditionPropertyMapping condition in conditionPropertyMappingList)
            {
                conditionTypeMappingFragment.RemoveConditionProperty(condition);
            }
            if (!entityType.Abstract)
            {
                return;
            }
            propertiesTypeMappingFragment.ClearConditions();
        }