/// <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 InternalEntityEntry TryGetEntry(object[] keyValues)
        {
            InternalEntityEntry entry;
            var key = PrincipalKeyValueFactory.CreateFromKeyValues(keyValues);

            return(key != null && _identityMap.TryGetValue((TKey)key, out entry) ? entry : null);
        }
Esempio n. 2
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 WeakReference <object> TryGetEntity(
            ValueBuffer valueBuffer,
            bool throwOnNullKey,
            out bool hasNullKey)
        {
            var key = PrincipalKeyValueFactory.CreateFromBuffer(valueBuffer);

            if (key == null)
            {
                if (throwOnNullKey)
                {
                    if (Key.IsPrimaryKey())
                    {
                        throw new InvalidOperationException(
                                  CoreStrings.InvalidKeyValue(
                                      Key.DeclaringEntityType.DisplayName(),
                                      PrincipalKeyValueFactory.FindNullPropertyInValueBuffer(valueBuffer).Name));
                    }

                    throw new InvalidOperationException(
                              CoreStrings.InvalidAlternateKeyValue(
                                  Key.DeclaringEntityType.DisplayName(),
                                  PrincipalKeyValueFactory.FindNullPropertyInValueBuffer(valueBuffer).Name));
                }

                hasNullKey = true;
                return(null);
            }

            hasNullKey = false;
            return(_identityMap.TryGetValue((TKey)key, out var entity) ? entity : null);
        }
Esempio n. 3
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 InternalEntityEntry TryGetEntry(ValueBuffer valueBuffer, bool throwOnNullKey)
        {
            var key = PrincipalKeyValueFactory.CreateFromBuffer(valueBuffer);

            if (key == null &&
                throwOnNullKey)
            {
                throw new InvalidOperationException(CoreStrings.InvalidKeyValue(Key.DeclaringEntityType.DisplayName()));
            }

            try
            {
                InternalEntityEntry entry;

                return(key != null &&
                       _identityMap.TryGetValue((TKey)key, out entry)
                    ? entry
                    : null);
            }
            catch (InvalidCastException e)
            {
                throw new InvalidOperationException(
                          // ReSharper disable once PossibleNullReferenceException
                          CoreStrings.ErrorMaterializingValueInvalidCast(typeof(TKey), key.GetType()),
                          e);
            }
        }
Esempio n. 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>
        protected virtual void Add([NotNull] TKey key, [NotNull] InternalEntityEntry entry)
        {
            InternalEntityEntry existingEntry;

            if (_identityMap.TryGetValue(key, out existingEntry))
            {
                if (existingEntry != entry)
                {
                    if (_sensitiveLoggingEnabled)
                    {
                        throw new InvalidOperationException(
                                  CoreStrings.IdentityConflictSensitive(
                                      entry.EntityType.DisplayName(),
                                      PrincipalKeyValueFactory.BuildKeyValuesString(entry)));
                    }

                    throw new InvalidOperationException(
                              CoreStrings.IdentityConflict(
                                  entry.EntityType.DisplayName(),
                                  string.Join(", ", Key.Properties.Select(p => p.Name))));
                }
            }
            else
            {
                AddInternal(key, entry);
            }
        }
Esempio n. 5
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 override void RemoveUsingRelationshipSnapshot(InternalEntityEntry entry)
        {
            var key = PrincipalKeyValueFactory.CreateFromRelationshipSnapshot(entry);

            if (key != null)
            {
                Remove(key, 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 override void Add(InternalEntityEntry entry)
        {
            var key = PrincipalKeyValueFactory.CreateFromCurrentValues(entry);

            if (key == null)
            {
                throw new InvalidOperationException(CoreStrings.InvalidKeyValue(entry.EntityType.DisplayName()));
            }

            Add(key, entry);
        }
Esempio n. 7
0
        public virtual InternalEntityEntry TryGetEntry(ValueBuffer valueBuffer, bool throwOnNullKey)
        {
            InternalEntityEntry entry;
            var key = PrincipalKeyValueFactory.CreateFromBuffer(valueBuffer);

            if (key == null &&
                throwOnNullKey)
            {
                throw new InvalidOperationException(CoreStrings.InvalidKeyValue(Key.DeclaringEntityType.DisplayName()));
            }
            return(key != null && _identityMap.TryGetValue((TKey)key, out entry) ? entry : null);
        }
Esempio n. 8
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 IIncludeKeyComparer CreateIncludeKeyComparer(INavigation navigation, InternalEntityEntry entry)
        {
            if (navigation.IsDependentToPrincipal())
            {
                return(navigation.ForeignKey.GetDependentKeyValueFactory <TKey>().TryCreateFromCurrentValues(entry, out var keyValue)
                    ? new DependentToPrincipalIncludeComparer <TKey>(keyValue, PrincipalKeyValueFactory)
                    : (IIncludeKeyComparer) new NullIncludeComparer());
            }

            return(new PrincipalToDependentIncludeComparer <TKey>(
                       PrincipalKeyValueFactory.CreateFromCurrentValues(entry),
                       navigation.ForeignKey.GetDependentKeyValueFactory <TKey>(),
                       PrincipalKeyValueFactory));
        }
Esempio n. 9
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 IIncludeKeyComparer CreateIncludeKeyComparer(INavigation navigation, ValueBuffer valueBuffer)
        {
            if (navigation.IsDependentToPrincipal())
            {
                return(navigation.ForeignKey.GetDependentKeyValueFactory <TKey>().TryCreateFromBuffer(valueBuffer, out var keyValue)
                    ? (IIncludeKeyComparer) new DependentToPrincipalIncludeComparer <TKey>(keyValue, PrincipalKeyValueFactory)
                    : new NullIncludeComparer());
            }

            return(new PrincipalToDependentIncludeComparer <TKey>(
                       (TKey)PrincipalKeyValueFactory.CreateFromBuffer(valueBuffer),
                       navigation.ForeignKey.GetDependentKeyValueFactory <TKey>(),
                       PrincipalKeyValueFactory));
        }
        public virtual WeakReference <object> TryGetEntity(ValueBuffer valueBuffer, out bool hasNullKey)
        {
            var key = PrincipalKeyValueFactory.CreateFromBuffer(valueBuffer);

            if (key == null)
            {
                hasNullKey = true;
                return(null);
            }

            hasNullKey = false;
            WeakReference <object> entity;

            return(_identityMap.TryGetValue((TKey)key, out entity) ? entity : null);
        }
Esempio n. 11
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 InternalEntityEntry TryGetEntry(ValueBuffer valueBuffer, bool throwOnNullKey)
        {
            var key = PrincipalKeyValueFactory.CreateFromBuffer(valueBuffer);

            if (key == null &&
                throwOnNullKey)
            {
                if (Key.IsPrimaryKey())
                {
                    throw new InvalidOperationException(
                              CoreStrings.InvalidKeyValue(
                                  Key.DeclaringEntityType.DisplayName(),
                                  PrincipalKeyValueFactory.FindNullPropertyInValueBuffer(valueBuffer).Name));
                }

                throw new InvalidOperationException(
                          CoreStrings.InvalidAlternateKeyValue(
                              Key.DeclaringEntityType.DisplayName(),
                              PrincipalKeyValueFactory.FindNullPropertyInValueBuffer(valueBuffer).Name));
            }

            try
            {
                return(key != null &&
                       _identityMap.TryGetValue((TKey)key, out var entry)
                    ? entry
                    : null);
            }
            catch (InvalidCastException e)
            {
                throw new InvalidOperationException(
                          // ReSharper disable once PossibleNullReferenceException
                          CoreStrings.ErrorMaterializingPropertyInvalidCast(
                              Key.DeclaringEntityType.DisplayName(),
                              Key.Properties.First().Name,
                              typeof(TKey),
                              key.GetType()),
                          e);
            }
        }
Esempio n. 12
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 override void Add(InternalEntityEntry entry)
        {
            var key = PrincipalKeyValueFactory.CreateFromCurrentValues(entry);

            if (key == null)
            {
                if (Key.IsPrimaryKey())
                {
                    throw new InvalidOperationException(
                              CoreStrings.InvalidKeyValue(
                                  entry.EntityType.DisplayName(),
                                  PrincipalKeyValueFactory.FindNullPropertyInCurrentValues(entry).Name));
                }

                throw new InvalidOperationException(
                          CoreStrings.InvalidAlternateKeyValue(
                              entry.EntityType.DisplayName(),
                              PrincipalKeyValueFactory.FindNullPropertyInCurrentValues(entry).Name));
            }

            Add(key, entry);
        }
Esempio n. 13
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 bool Contains(ValueBuffer valueBuffer)
        {
            var key = PrincipalKeyValueFactory.CreateFromBuffer(valueBuffer);

            return(key != null && _identityMap.ContainsKey((TKey)key));
        }
Esempio n. 14
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 RemoveUsingRelationshipSnapshot(InternalEntityEntry entry)
 => Remove(PrincipalKeyValueFactory.CreateFromRelationshipSnapshot(entry), entry);
Esempio n. 15
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 Remove(InternalEntityEntry entry)
 => Remove(PrincipalKeyValueFactory.CreateFromCurrentValues(entry), entry);
Esempio n. 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 Add(object[] keyValues, InternalEntityEntry entry)
 => Add((TKey)PrincipalKeyValueFactory.CreateFromKeyValues(keyValues), entry);
Esempio n. 17
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 AddOrUpdate(InternalEntityEntry entry)
 => AddInternal(PrincipalKeyValueFactory.CreateFromCurrentValues(entry), entry);
 public virtual void Add(ValueBuffer valueBuffer, object entity)
 => _identityMap[(TKey)PrincipalKeyValueFactory.CreateFromBuffer(valueBuffer)] = new WeakReference <object>(entity);