Exemple #1
0
        private void DetectKeyChanges(StateEntry entry, Sidecar snapshot)
        {
            var entityType = entry.EntityType;

            if (!entityType.HasPropertyChangedNotifications())
            {
                foreach (var property in entityType.Properties)
                {
                    DetectKeyChange(entry, property, snapshot);
                }
            }
        }
Exemple #2
0
        private void DetectNavigationChanges(StateEntry entry, Sidecar snapshot)
        {
            var entityType = entry.EntityType;

            if (!entityType.HasPropertyChangedNotifications() ||
                entityType.Navigations.Any(n => n.IsNonNotifyingCollection(entry)))
            {
                foreach (var navigation in entityType.Navigations)
                {
                    TrackAddedEntities(entry.StateManager, DetectNavigationChange(entry, navigation, snapshot));
                }
            }
        }
Exemple #3
0
        private async Task DetectNavigationChangesAsync(
            StateEntry entry, Sidecar snapshot, CancellationToken cancellationToken = default(CancellationToken))
        {
            var entityType = entry.EntityType;

            if (!entityType.HasPropertyChangedNotifications() ||
                entityType.Navigations.Any(n => n.IsNonNotifyingCollection(entry)))
            {
                foreach (var navigation in entityType.Navigations)
                {
                    await TrackAddedEntitiesAsync(entry.StateManager, DetectNavigationChange(entry, navigation, snapshot), cancellationToken)
                    .WithCurrentCulture();
                }
            }
        }
Exemple #4
0
        public virtual Sidecar AddSidecar([NotNull] Sidecar sidecar)
        {
            Check.NotNull(sidecar, "sidecar");

            var newArray = new[] { sidecar };

            _sidecars = _sidecars == null
                ? newArray
                : newArray.Concat(_sidecars).ToArray();

            if (sidecar.TransparentRead ||
                sidecar.TransparentWrite ||
                sidecar.AutoCommit)
            {
                _stateData.TransparentSidecarInUse = true;
            }

            return(sidecar);
        }
Exemple #5
0
        private void DetectKeyChange(StateEntry entry, IProperty property, Sidecar snapshot)
        {
            if (!snapshot.HasValue(property))
            {
                return;
            }

            // TODO: Perf: make it fast to check if a property is part of any key
            var isPrimaryKey   = property.IsPrimaryKey();
            var isPrincipalKey = _model.Service.GetReferencingForeignKeys(property).Any();
            var isForeignKey   = property.IsForeignKey();

            if (isPrimaryKey ||
                isPrincipalKey ||
                isForeignKey)
            {
                var snapshotValue = snapshot[property];
                var currentValue  = entry[property];

                // Note that mutation of a byte[] key is not supported or detected, but two different instances
                // of byte[] with the same content must be detected as equal.
                if (!StructuralComparisons.StructuralEqualityComparer.Equals(currentValue, snapshotValue))
                {
                    if (isForeignKey)
                    {
                        entry.StateManager.Notify.ForeignKeyPropertyChanged(entry, property, snapshotValue, currentValue);
                    }

                    if (isPrimaryKey)
                    {
                        entry.StateManager.UpdateIdentityMap(entry, snapshot.GetPrimaryKeyValue());
                    }

                    if (isPrincipalKey)
                    {
                        entry.StateManager.Notify.PrincipalKeyPropertyChanged(entry, property, snapshotValue, currentValue);
                    }

                    snapshot.TakeSnapshot(property);
                }
            }
        }
Exemple #6
0
        private IEnumerable <object> DetectNavigationChange(StateEntry entry, INavigation navigation, Sidecar snapshot)
        {
            var snapshotValue = snapshot[navigation];
            var currentValue  = entry[navigation];
            var stateManager  = entry.StateManager;

            var added = new HashSet <object>(ReferenceEqualityComparer.Instance);

            if (navigation.IsCollection())
            {
                var snapshotCollection = (IEnumerable)snapshotValue;
                var currentCollection  = (IEnumerable)currentValue;

                var removed = new HashSet <object>(ReferenceEqualityComparer.Instance);
                if (snapshotCollection != null)
                {
                    foreach (var entity in snapshotCollection)
                    {
                        removed.Add(entity);
                    }
                }

                if (currentCollection != null)
                {
                    foreach (var entity in currentCollection)
                    {
                        if (!removed.Remove(entity))
                        {
                            added.Add(entity);
                        }
                    }
                }

                if (added.Any() ||
                    removed.Any())
                {
                    stateManager.Notify.NavigationCollectionChanged(entry, navigation, added, removed);

                    snapshot.TakeSnapshot(navigation);
                }
            }
            else if (!ReferenceEquals(currentValue, snapshotValue))
            {
                stateManager.Notify.NavigationReferenceChanged(entry, navigation, snapshotValue, currentValue);

                if (currentValue != null)
                {
                    added.Add(currentValue);
                }

                snapshot.TakeSnapshot(navigation);
            }

            return(added);
        }
        public override EntityKey Create(IEntityType entityType, IReadOnlyList <IProperty> properties, Sidecar sidecar)
        {
            Check.NotNull(entityType, "entityType");
            Check.NotNull(properties, "properties");
            Check.NotNull(sidecar, "sidecar");

            return(Create(entityType, sidecar[properties[0]]));
        }
 public abstract EntityKey Create(
     [NotNull] IEntityType entityType, [NotNull] IReadOnlyList <IProperty> properties, [NotNull] Sidecar sidecar);
Exemple #9
0
        public override EntityKey Create(IEntityType entityType, IReadOnlyList <IProperty> properties, Sidecar sidecar)
        {
            Check.NotNull(entityType, "entityType");
            Check.NotNull(properties, "properties");
            Check.NotNull(sidecar, "sidecar");

            return(Create(entityType, properties.Select(p => sidecar[p]).ToArray()));
        }