src/Shared/EntityFramework/Internal/Validation/ValidationAttributeValidator.cs
// <summary>
// Validates a property or an entity.
// </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>
// Validation errors as <see cref="IEnumerable{DbValidationError}" /> . Empty if no errors, never null.
// </returns>
Validates a property or an entity.
Validates a property or an entity .
public virtual IEnumerable<DbValidationError> Validate(
            EntityValidationContext entityValidationContext, InternalMemberEntry property)
        {
            DebugCheck.NotNull(entityValidationContext);
            if (!AttributeApplicable(entityValidationContext, property))
            {
                return Enumerable.Empty<DbValidationError>();
            }
            var validationContext = entityValidationContext.ExternalValidationContext;
            validationContext.SetDisplayName(property, _displayAttribute);
            var objectToValidate = property == null
                                       ? entityValidationContext.InternalEntity.Entity
                                       : property.CurrentValue;
            ValidationResult validationResult = null;
            try
            {
                validationResult = _validationAttribute.GetValidationResult(objectToValidate, validationContext);
            }
            catch (Exception ex)
            {
                throw new DbUnexpectedValidationException(
                    Strings.DbUnexpectedValidationException_ValidationAttribute(
                        validationContext.DisplayName, _validationAttribute.GetType()),
                    ex);
            }
            return validationResult != ValidationResult.Success
                       ? DbHelpers.SplitValidationResults(validationContext.MemberName, new[] { validationResult })
                       : Enumerable.Empty<DbValidationError>();
        }
public virtual IEnumerable < DbValidationError > Validate ( EntityValidationContext entityValidationContext , InternalMemberEntry property ) { DebugCheck . NotNull ( entityValidationContext ) ; if ( ! AttributeApplicable ( entityValidationContext , property ) ) { return Enumerable . Empty < DbValidationError > ( ) ; } var validationContext = entityValidationContext . ExternalValidationContext ; validationContext . SetDisplayName ( property , _displayAttribute ) ; var objectToValidate = property == null ? entityValidationContext . InternalEntity . Entity : property . CurrentValue ; ValidationResult validationResult = null ; try { validationResult = _validationAttribute . GetValidationResult ( objectToValidate , validationContext ) ; } catch ( Exception ex ) { throw new DbUnexpectedValidationException ( Strings . DbUnexpectedValidationException_ValidationAttribute ( validationContext . DisplayName , _validationAttribute . GetType ( ) ) , ex ) ; } return validationResult != ValidationResult . Success ? DbHelpers . SplitValidationResults ( validationContext . MemberName , new [ ] { validationResult } ) : Enumerable . Empty < DbValidationError > ( ) ; }
Validates a property or an entity.
Validates a property or an entity .
Validation errors as  . Empty if no errors, never null.
Validation errors as . Empty if no errors never null .
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 .