Esempio n. 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 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. 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 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. 3
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. 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>
        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. 6
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. 7
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));
        }
 public virtual void Add(ValueBuffer valueBuffer, object entity)
 => _identityMap[(TKey)PrincipalKeyValueFactory.CreateFromBuffer(valueBuffer)] = new WeakReference <object>(entity);