src/Shared/EntityFramework/Internal/EntityEntries/InternalEntityEntry.cs
// <summary>
// Checks that the given property name is a navigation property and is either a reference property or
// collection property according to the value of requireCollection.
// </summary>
Checks that the given property name is a navigation property and is either a reference property or
collection property according to the value of requireCollection.
Checks that the given property name is a navigation property and is either a reference property or collection property according to the value of requireCollection .
private NavigationEntryMetadata ValidateAndGetNavigationMetadata(
            string navigationProperty, Type requestedType, bool requireCollection)
        {
            if (SplitName(navigationProperty).Count != 1)
            {
                throw Error.DbEntityEntry_DottedPathMustBeProperty(navigationProperty);
            }
            var propertyMetadata = GetNavigationMetadata(navigationProperty);
            if (propertyMetadata == null)
            {
                throw Error.DbEntityEntry_NotANavigationProperty(navigationProperty, EntityType.Name);
            }
            if (requireCollection)
            {
                if (propertyMetadata.MemberEntryType
                    == MemberEntryType.ReferenceNavigationProperty)
                {
                    throw Error.DbEntityEntry_UsedCollectionForReferenceProp(navigationProperty, EntityType.Name);
                }
            }
            else if (propertyMetadata.MemberEntryType
                     == MemberEntryType.CollectionNavigationProperty)
            {
                throw Error.DbEntityEntry_UsedReferenceForCollectionProp(navigationProperty, EntityType.Name);
            }
            if (!requestedType.IsAssignableFrom(propertyMetadata.ElementType))
            {
                throw Error.DbEntityEntry_WrongGenericForNavProp(
                    navigationProperty, EntityType.Name, requestedType.Name, propertyMetadata.ElementType.Name);
            }
            return propertyMetadata;
        }
private NavigationEntryMetadata ValidateAndGetNavigationMetadata ( string navigationProperty , Type requestedType , bool requireCollection ) { if ( SplitName ( navigationProperty ) . Count != 1 ) { throw Error . DbEntityEntry_DottedPathMustBeProperty ( navigationProperty ) ; } var propertyMetadata = GetNavigationMetadata ( navigationProperty ) ; if ( propertyMetadata == null ) { throw Error . DbEntityEntry_NotANavigationProperty ( navigationProperty , EntityType . Name ) ; } if ( requireCollection ) { if ( propertyMetadata . MemberEntryType == MemberEntryType . ReferenceNavigationProperty ) { throw Error . DbEntityEntry_UsedCollectionForReferenceProp ( navigationProperty , EntityType . Name ) ; } } else if ( propertyMetadata . MemberEntryType == MemberEntryType . CollectionNavigationProperty ) { throw Error . DbEntityEntry_UsedReferenceForCollectionProp ( navigationProperty , EntityType . Name ) ; } if ( ! requestedType . IsAssignableFrom ( propertyMetadata . ElementType ) ) { throw Error . DbEntityEntry_WrongGenericForNavProp ( navigationProperty , EntityType . Name , requestedType . Name , propertyMetadata . ElementType . Name ) ; } return propertyMetadata ; }
Checks that the given property name is a navigation property and is either a reference property or
collection property according to the value of requireCollection.
Checks that the given property name is a navigation property and is either a reference property or collection property according to the value of requireCollection .
navigationProperty
string
requestedType
Type
requireCollection
bool