Exemple #1
0
        private static void ProcessModifiedEntity(List <ModifiedObjectMetadata> modifyObjectsMetada, InternalEntityEntry entityEntry, ChangeTracker changeTracker)
        {
            ModifiedObjectMetadata      modifyObjectMetada = GetOrCreateMetaData(modifyObjectsMetada, entityEntry.Entity);
            IEnumerable <PropertyEntry> properties         = entityEntry.GetProperties();

            ProcessProperties(entityEntry.Entity, modifyObjectMetada, properties);
            ProcessNavigations(entityEntry, modifyObjectsMetada, modifyObjectMetada, properties, changeTracker);
        }
Exemple #2
0
        private static ModifiedObjectMetadata GetOrCreateMetaData(List <ModifiedObjectMetadata> modifiedObjectMetadataList, object targetObject)
        {
            ModifiedObjectMetadata modifiedObjectMetadata = modifiedObjectMetadataList.FirstOrDefault(p => Equals(p.Object, targetObject));

            if (modifiedObjectMetadata == null)
            {
                modifiedObjectMetadata = new ModifiedObjectMetadata(targetObject);
                modifiedObjectMetadataList.Add(modifiedObjectMetadata);
            }
            return(modifiedObjectMetadata);
        }
Exemple #3
0
        private static void ProcessPrincipalEntity(InternalEntityEntry entityEntry, List <ModifiedObjectMetadata> modifyObjectsMetada, IForeignKey foreignKey, InternalEntityEntry principaEntityEntry)
        {
            ModifiedObjectMetadata    modifyObjectMetadaNavigation = GetOrCreateMetaData(modifyObjectsMetada, principaEntityEntry.Entity);
            IEnumerable <INavigation> findNavigationsTo            = foreignKey.FindNavigationsFrom(principaEntityEntry.EntityType);

            foreach (var entityNavigation in findNavigationsTo)
            {
                if (!modifyObjectMetadaNavigation.NavigationProperties.Contains(entityNavigation.Name))
                {
                    modifyObjectMetadaNavigation.NavigationProperties.Add(entityNavigation.Name);
                }
            }
        }
Exemple #4
0
 private static void ProcessProperties(object targetObject, ModifiedObjectMetadata modifiedObjectMetadata, IEnumerable <PropertyEntry> properties)
 {
     foreach (PropertyEntry propertyEntry in properties)
     {
         if (propertyEntry.IsModified)
         {
             if (propertyEntry.Metadata.IsKeyOrForeignKey())
             {
                 continue;
             }
             modifiedObjectMetadata.Properties.Add(propertyEntry.Metadata.Name, propertyEntry.CurrentValue);
         }
     }
 }
Exemple #5
0
        private static void ProcessNavigations(InternalEntityEntry entityEntry, List <ModifiedObjectMetadata> modifyObjectsMetada, ModifiedObjectMetadata modifyObjectMetada, IEnumerable <PropertyEntry> properties, ChangeTracker changeTracker)
        {
            IEnumerable <IForeignKey> foreignKeys = entityEntry.EntityType.GetForeignKeys();

            foreach (IForeignKey foreignKey in foreignKeys)
            {
                for (int i = 0; i < foreignKey.Properties.Count(); i++)
                {
                    PropertyEntry propertyEntry = properties.First(p => p.Metadata.Name == foreignKey.Properties[0].Name);
                    if (!propertyEntry.IsModified && entityEntry.EntityState != EntityState.Added)
                    {
                        continue;
                    }
                    modifyObjectMetada.ForeignKeys.Add(propertyEntry.Metadata.Name, propertyEntry.CurrentValue);
                    IEnumerable <INavigation> findNavigationsToForeign = foreignKey.FindNavigationsFrom(entityEntry.EntityType);
                    foreach (INavigation nav in findNavigationsToForeign)
                    {
                        modifyObjectMetada.NavigationProperties.Add(nav.Name);
                    }

                    InternalEntityEntry principaEntityEntryOriginalValue = changeTracker.GetPrincipaEntityEntryOriginalValue(entityEntry, foreignKey);
                    if (principaEntityEntryOriginalValue != null)
                    {
                        ProcessPrincipalEntity(entityEntry, modifyObjectsMetada, foreignKey, principaEntityEntryOriginalValue);
                    }
                    InternalEntityEntry principaEntityEntryCurrentValue = changeTracker.GetPrincipalEntityEntryCurrentValue(entityEntry, foreignKey);
                    if (principaEntityEntryCurrentValue != null)
                    {
                        ProcessPrincipalEntity(entityEntry, modifyObjectsMetada, foreignKey, principaEntityEntryCurrentValue);
                    }
                }
            }
        }