예제 #1
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 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);
                    }
                }
            }
        }
예제 #2
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 (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);
        }
    }
예제 #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
 public void RemoveFromCollection(IPropertyBase propertyBase, object removedEntity)
 {
     var index = propertyBase.GetRelationshipIndex();
     if (index != -1)
     {
         ((HashSet<object>)_values[index])?.Remove(removedEntity);
     }
 }
예제 #5
0
            public void AddToCollection(IPropertyBase propertyBase, object addedEntity)
            {
                var index = propertyBase.GetRelationshipIndex();
                if (index != -1)
                {
                    var snapshot = GetOrCreateCollection(index);

                    snapshot.Add(addedEntity);
                }
            }
예제 #6
0
        public virtual void PropertyChanging(InternalEntityEntry entry, IPropertyBase propertyBase)
        {
            if (!entry.EntityType.UseEagerSnapshots())
            {
                entry.EnsureOriginalValues();

                if (propertyBase.GetRelationshipIndex() != -1)
                {
                    entry.EnsureRelationshipSnapshot();
                }
            }
        }
예제 #7
0
            public void AddRangeToCollection(IPropertyBase propertyBase, IEnumerable<object> addedEntities)
            {
                var index = propertyBase.GetRelationshipIndex();
                if (index != -1)
                {
                    var snapshot = GetOrCreateCollection(index);

                    foreach (var addedEntity in addedEntities)
                    {
                        snapshot.Add(addedEntity);
                    }
                }
            }
            public void AddToCollection(IPropertyBase propertyBase, object addedEntity)
            {
                var index = propertyBase.GetRelationshipIndex();

                var snapshot = (HashSet <object>)_values[index];

                if (snapshot == null)
                {
                    snapshot       = new HashSet <object>(ReferenceEqualityComparer.Instance);
                    _values[index] = snapshot;
                }

                snapshot.Add(addedEntity);
            }
            public void SetValue(IPropertyBase propertyBase, object value)
            {
                if (value == null)
                {
                    if (propertyBase is IProperty property &&
                        !property.IsNullable)
                    {
                        return;
                    }
                }

                Debug.Assert(!IsEmpty);
                Debug.Assert(!(propertyBase is INavigation) || !((INavigation)propertyBase).IsCollection());

                _values[propertyBase.GetRelationshipIndex()] = value;
            }
예제 #10
0
        public virtual void PropertyChanging(InternalEntityEntry entry, IPropertyBase propertyBase)
        {
            if (_suspended)
            {
                return;
            }

            if (!entry.EntityType.UseEagerSnapshots())
            {
                entry.EnsureOriginalValues();

                if (propertyBase.GetRelationshipIndex() != -1)
                {
                    entry.EnsureRelationshipSnapshot();
                }
            }
        }
예제 #11
0
            public void SetValue(IPropertyBase propertyBase, object value)
            {
                if (value == null)
                {
                    if (propertyBase is IProperty property
                        && !property.IsNullable)
                    {
                        return;
                    }
                }

                Check.DebugAssert(!IsEmpty, "relationship snapshot is empty");
                Check.DebugAssert(
                    !(propertyBase is INavigation) || !((INavigation)propertyBase).IsCollection(),
                    $"property {propertyBase} is is not reference navigation");

                _values[propertyBase.GetRelationshipIndex()] = SnapshotValue(propertyBase, value);
            }
예제 #12
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 PropertyChanging(InternalEntityEntry entry, IPropertyBase propertyBase)
        {
            if (_suspended || entry.EntityState == EntityState.Detached)
            {
                return;
            }

            if (!entry.EntityType.UseEagerSnapshots())
            {
                if (propertyBase is IProperty asProperty &&
                    asProperty.GetOriginalValueIndex() != -1)
                {
                    entry.EnsureOriginalValues();
                }

                if (propertyBase.GetRelationshipIndex() != -1)
                {
                    entry.EnsureRelationshipSnapshot();
                }
            }
        }
예제 #13
0
 public object GetValue(InternalEntityEntry entry, IPropertyBase propertyBase)
     => IsEmpty ? entry[propertyBase] : _values[propertyBase.GetRelationshipIndex()];
 public void RemoveFromCollection(IPropertyBase propertyBase, object removedEntity)
 => ((HashSet <object>)_values[propertyBase.GetRelationshipIndex()]).Remove(removedEntity);
 /// <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>
 protected override int GetPropertyIndex(IPropertyBase propertyBase)
 => propertyBase.GetRelationshipIndex();
예제 #16
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 PropertyChanging(InternalEntityEntry entry, IPropertyBase propertyBase)
        {
            if (_suspended || entry.EntityState == EntityState.Detached)
            {
                return;
            }

            if (!entry.EntityType.UseEagerSnapshots())
            {
                var asProperty = propertyBase as IProperty;
                if (asProperty != null
                    && asProperty.GetOriginalValueIndex() != -1)
                {
                    entry.EnsureOriginalValues();
                }

                if (propertyBase.GetRelationshipIndex() != -1)
                {
                    entry.EnsureRelationshipSnapshot();
                }
            }
        }