Example #1
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 IClrCollectionAccessor Create(
            [NotNull] INavigation navigation,
            bool forConstruction = false,
            bool forSet          = false)
        {
            // ReSharper disable once SuspiciousTypeConversion.Global
            if (navigation is IClrCollectionAccessor accessor)
            {
                return(accessor);
            }

            var property     = navigation.GetIdentifyingMemberInfo();
            var propertyType = property.GetMemberType();
            var elementType  = propertyType.TryGetElementType(typeof(IEnumerable <>));

            if (elementType == null)
            {
                throw new InvalidOperationException(
                          CoreStrings.NavigationBadType(
                              navigation.Name,
                              navigation.DeclaringEntityType.DisplayName(),
                              propertyType.ShortDisplayName(),
                              navigation.GetTargetType().DisplayName()));
            }

            if (propertyType.IsArray)
            {
                throw new InvalidOperationException(
                          CoreStrings.NavigationArray(
                              navigation.Name,
                              navigation.DeclaringEntityType.DisplayName(),
                              propertyType.ShortDisplayName()));
            }

            var boundMethod = _genericCreate.MakeGenericMethod(
                property.DeclaringType, propertyType, elementType);

            var memberInfo = navigation.GetMemberInfo(forConstruction, forSet);

            return((IClrCollectionAccessor)boundMethod.Invoke(
                       null, new object[]
            {
                navigation, memberInfo
            }));
        }
 /// <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 static MemberIdentity CreateMemberIdentity([CanBeNull] this INavigation navigation)
 => navigation?.GetIdentifyingMemberInfo() == null
         ? MemberIdentity.Create(navigation?.Name)
         : MemberIdentity.Create(navigation.GetIdentifyingMemberInfo());
 public static MemberIdentity Create([CanBeNull] INavigation navigation)
 => navigation?.GetIdentifyingMemberInfo() == null
         ? Create(navigation?.Name)
         : Create(navigation.GetIdentifyingMemberInfo());