示例#1
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))
                        {
                            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);
                }

                foreach (var navigation in entityType.GetSkipNavigations())
                {
                    DetectNavigationChange(entry, navigation);
                }
            }
        }
示例#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);
                }
            }
        }
示例#3
0
        public virtual void PropertyChanged(InternalEntityEntry entry, IPropertyBase propertyBase, bool setModified)
        {
            if (_suspended || entry.EntityState == EntityState.Detached)
            {
                return;
            }

            var property = propertyBase as IProperty;

            if (property != null)
            {
                entry.SetPropertyModified(property, setModified);

                if (property.GetRelationshipIndex() != -1)
                {
                    DetectKeyChange(entry, property);
                }
            }
            else
            {
                if (propertyBase.GetRelationshipIndex() != -1)
                {
                    var navigation = propertyBase as INavigation;
                    if (navigation != null)
                    {
                        DetectNavigationChange(entry, navigation);
                    }
                }
            }
        }
示例#4
0
        /// <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 virtual void PropertyChanged(InternalEntityEntry entry, IPropertyBase propertyBase, bool setModified)
        {
            if (_suspended ||
                entry.EntityState == EntityState.Detached ||
                propertyBase is IServiceProperty)
            {
                return;
            }

            if (propertyBase is IProperty property)
            {
                if (entry.EntityState != EntityState.Deleted)
                {
                    entry.SetPropertyModified(property, setModified);
                }
                else
                {
                    ThrowIfKeyChanged(entry, property);
                }

                DetectKeyChange(entry, property);
            }
            else if (propertyBase.GetRelationshipIndex() != -1 &&
                     propertyBase is INavigationBase navigation)
            {
                DetectNavigationChange(entry, navigation);
            }
        }
        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);
        }
        /// <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.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))
                        {
                            entry.SetPropertyModified(property);
                        }
                    }
                    else
                    {
                        if (!comparer.CompareFunc(current, original))
                        {
                            entry.SetPropertyModified(property);
                        }
                    }
                }
            }

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

            if (entry.HasRelationshipSnapshot)
            {
                foreach (var navigation in entityType.GetNavigations())
                {
                    DetectNavigationChange(entry, navigation);
                }
            }
        }
示例#7
0
        /// <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);
                }
            }
        }
示例#8
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);
                }
            }
        }