Esempio n. 1
0
        public virtual void PropertyChanged(StateEntry entry, IPropertyBase propertyBase)
        {
            Check.NotNull(entry, "entry");
            Check.NotNull(propertyBase, "propertyBase");

            var snapshot = entry.TryGetSidecar(Sidecar.WellKnownNames.RelationshipsSnapshot);

            var property = propertyBase as IProperty;

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

                if (snapshot != null)
                {
                    DetectKeyChange(entry, property, snapshot);
                }
            }
            else
            {
                var navigation = propertyBase as INavigation;
                if (navigation != null &&
                    snapshot != null)
                {
                    TrackAddedEntities(entry.StateManager, DetectNavigationChange(entry, navigation, snapshot));
                }
            }
        }
Esempio n. 2
0
        public virtual void PropertyChanged([NotNull] StateEntry entry, [NotNull] IPropertyBase propertyBase)
        {
            Check.NotNull(entry, "entry");
            Check.NotNull(propertyBase, "propertyBase");

            var property = propertyBase as IProperty;

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

                // Note: Make sure DetectPrincipalKeyChange is called even if DetectForeignKeyChange has returned true
                var foreignKeyChange   = DetectForeignKeyChange(entry, property);
                var principalKeyChange = DetectPrincipalKeyChange(entry, property);
                if (foreignKeyChange ||
                    principalKeyChange)
                {
                    entry.RelationshipsSnapshot.TakeSnapshot(property);
                }
            }
            else
            {
                var navigation = propertyBase as INavigation;

                if (navigation != null)
                {
                    if (DetectNavigationChange(entry, navigation))
                    {
                        entry.RelationshipsSnapshot.TakeSnapshot(navigation);
                    }
                }
            }
        }
Esempio n. 3
0
        private void DetectPropertyChanges(StateEntry entry)
        {
            var entityType = entry.EntityType;

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

            var snapshot = entry.TryGetSidecar(Sidecar.WellKnownNames.OriginalValues);

            if (snapshot == null)
            {
                return;
            }

            foreach (var property in entityType.Properties)
            {
                if (property.OriginalValueIndex >= 0 &&
                    !Equals(entry[property], snapshot[property]))
                {
                    entry.SetPropertyModified(property);
                }
            }
        }
Esempio n. 4
0
        public virtual bool DetectChanges([NotNull] StateEntry entry)
        {
            Check.NotNull(entry, "entry");

            var entityType     = entry.EntityType;
            var originalValues = entry.TryGetSidecar(Sidecar.WellKnownNames.OriginalValues);

            // TODO: Consider more efficient/higher-level/abstract mechanism for checking if DetectChanges is needed
            // See issue #731
            if (entityType.Type == null ||
                originalValues == null ||
                typeof(INotifyPropertyChanged).GetTypeInfo().IsAssignableFrom(entityType.Type.GetTypeInfo()))
            {
                return(false);
            }

            var changedFkProperties = new List <IProperty>();
            var foundChanges        = false;

            foreach (var property in entityType.Properties)
            {
                // TODO: Perf: don't lookup accessor twice
                if (!Equals(entry[property], originalValues[property]))
                {
                    entry.SetPropertyModified(property);
                    foundChanges = true;
                }

                if (DetectForeignKeyChange(entry, property))
                {
                    changedFkProperties.Add(property);
                }
            }

            foreach (var property in changedFkProperties)
            {
                entry.RelationshipsSnapshot.TakeSnapshot(property);
            }

            foreach (var navigation in entityType.Navigations)
            {
                if (DetectNavigationChange(entry, navigation))
                {
                    entry.RelationshipsSnapshot.TakeSnapshot(navigation);
                }
            }

            return(foundChanges);
        }