public override void DetectChanges(InternalEntityEntry entry)
        {
            var entityType = entry.EntityType;

            var properties = entityType.GetProperties();

            foreach (var property in properties)
            {
                var          current          = entry[property];
                var          old              = entry.GetOriginalValue(property);
                var          flag             = current != null && current.GetType().Name == typeof(JsonObject <>).Name;
                TypeInfo     type             = null;
                PropertyInfo originalProperty = null;
                if (flag)
                {
                    type             = current.GetType().GetTypeInfo();
                    originalProperty = type.DeclaredProperties.Single(x => x.Name == "_originalValue");
                    old = (string)originalProperty.GetValue(current);
                    var prop = type.DeclaredProperties.Single(x => x.Name == "Json");
                    current = (string)prop.GetValue(current);
                }
                if (property.GetOriginalValueIndex() >= 0 &&
                    (!Equals(entry[property], entry.GetOriginalValue(property)) || flag && current != old))
                {
                    entry.SetPropertyModified(property);
                    if (flag)
                    {
                        originalProperty.SetValue(entry[property], current);
                    }
                }
            }

            base.DetectChanges(entry);
        }
Beispiel #2
0
        public virtual void DetectChanges(InternalEntityEntry entry)
        {
            var entityType = entry.EntityType;

            foreach (var property in entityType.GetProperties())
            {
                if (property.GetOriginalValueIndex() >= 0 &&
                    !Equals(entry[property], entry.GetOriginalValue(property)))
                {
                    entry.SetPropertyModified(property);
                }
            }

            foreach (var property in entityType.GetProperties())
            {
                DetectKeyChange(entry, property);
            }

            if (entry.HasRelationshipSnapshot)
            {
                foreach (var navigation in entityType.GetNavigations())
                {
                    DetectNavigationChange(entry, navigation);
                }
            }
        }
Beispiel #3
0
        private void LocalDetectChanges(InternalEntityEntry entry)
        {
            var entityType = entry.EntityType;

            foreach (var property in entityType.GetProperties())
            {
                if (property.GetOriginalValueIndex() >= 0 &&
                    !entry.IsModified(property) &&
                    !entry.IsConceptualNull(property))
                {
                    var current  = entry[property];
                    var original = entry.GetOriginalValue(property);

                    var comparer = property.GetValueComparer();

                    if (comparer == null)
                    {
                        if (!Equals(current, original))
                        {
                            SetPropertyModified();
                        }
                    }
                    else if (!comparer.Equals(current, original))
                    {
                        SetPropertyModified();
                    }

                    void SetPropertyModified()
                    {
                        if (entry.EntityState == EntityState.Deleted)
                        {
                            ThrowIfKeyChanged(entry, property);
                        }
                        else
                        {
                            LogChangeDetected(entry, property, original, current);
                            entry.SetPropertyModified(property);
                        }
                    }
                }
            }

            foreach (var property in entityType.GetProperties())
            {
                DetectKeyChange(entry, property);
            }

            if (entry.HasRelationshipSnapshot)
            {
                foreach (var navigation in entityType.GetNavigations())
                {
                    DetectNavigationChange(entry, navigation);
                }

                foreach (var navigation in entityType.GetSkipNavigations())
                {
                    DetectNavigationChange(entry, navigation);
                }
            }
        }
Beispiel #4
0
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        public virtual void DetectChanges(InternalEntityEntry entry)
        {
            var entityType = entry.EntityType;

            foreach (var property in entityType.GetProperties())
            {
                if (property.GetOriginalValueIndex() >= 0 &&
                    !entry.IsModified(property) &&
                    !entry.IsConceptualNull(property))
                {
                    var current  = entry[property];
                    var original = entry.GetOriginalValue(property);

                    var comparer = property.GetValueComparer() ?? property.FindMapping()?.Comparer;

                    if (comparer == null)
                    {
                        if (!Equals(current, original))
                        {
                            LogChangeDetected(entry, property, original, current);
                            entry.SetPropertyModified(property);
                        }
                    }
                    else
                    {
                        if (!comparer.Equals(current, original))
                        {
                            LogChangeDetected(entry, property, original, current);
                            entry.SetPropertyModified(property);
                        }
                    }
                }
            }

            foreach (var property in entityType.GetProperties())
            {
                DetectKeyChange(entry, property);
            }

            if (entry.HasRelationshipSnapshot)
            {
                foreach (var navigation in entityType.GetNavigations())
                {
                    DetectNavigationChange(entry, navigation);
                }
            }
        }
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public void DetectValueChange(InternalEntityEntry entry, IProperty property)
        {
            var current  = entry[property];
            var original = entry.GetOriginalValue(property);

            if (!property.GetValueComparer().Equals(current, original))
            {
                if (entry.EntityState == EntityState.Deleted)
                {
                    ThrowIfKeyChanged(entry, property);
                }
                else
                {
                    LogChangeDetected(entry, property, original, current);
                    entry.SetPropertyModified(property);
                }
            }
        }
Beispiel #6
0
        private static void DetectPropertyChanges(InternalEntityEntry entry)
        {
            var entityType = entry.EntityType;

            if (entityType.HasPropertyChangedNotifications())
            {
                return;
            }

            foreach (var property in entityType.GetProperties())
            {
                if (property.GetOriginalValueIndex() >= 0 &&
                    !Equals(entry[property], entry.GetOriginalValue(property)))
                {
                    entry.SetPropertyModified(property);
                }
            }
        }