src/EntityFramework/Internal/Validation/ValidationAttributeValidator.cs
// <summary>
// Determines if the attribute should be enforced given the context of the validation request.
// </summary>
// <param name="entityValidationContext"> Validation context. Never null. </param>
// <param name="property"> Property to validate. Null for entity validation. Not null for property validation. </param>
// <returns> True if the attribute should be enforced; otherwise false. </returns>
Determines if the attribute should be enforced given the context of the validation request.
Determines if the attribute should be enforced given the context of the validation request .
protected virtual bool AttributeApplicable(
            EntityValidationContext entityValidationContext, InternalMemberEntry property)
        {
            var internalNavigationProperty = property as InternalNavigationEntry;
            if (_validationAttribute is RequiredAttribute &&
                property != null && property.InternalEntityEntry != null &&
                property.InternalEntityEntry.State != EntityState.Added && property.InternalEntityEntry.State != EntityState.Detached &&
                internalNavigationProperty != null && !internalNavigationProperty.IsLoaded)
            {
                return false;
            }
            return true;
        }
protected virtual bool AttributeApplicable ( EntityValidationContext entityValidationContext , InternalMemberEntry property ) { var internalNavigationProperty = property as InternalNavigationEntry ; if ( _validationAttribute is RequiredAttribute && property != null && property . InternalEntityEntry != null && property . InternalEntityEntry . State != EntityState . Added && property . InternalEntityEntry . State != EntityState . Detached && internalNavigationProperty != null && ! internalNavigationProperty . IsLoaded ) { return false ; } return true ; }
Determines if the attribute should be enforced given the context of the validation request.
Determines if the attribute should be enforced given the context of the validation request .
// Do not apply RequiredAttrbiute to existing entities when the property is // a navigation property and it has not been loaded.
True if the attribute should be enforced; otherwise false.
True if the attribute should be enforced ; otherwise false .
entityValidationContext
EntityValidationContext
Validation context. Never null.
Validation context . Never null .
property
InternalMemberEntry
Property to validate. Null for entity validation. Not null for property validation.
Property to validate . Null for entity validation . Not null for property validation .