src/Shared/EntityFramework/Internal/Validation/EntityValidatorBuilder.cs
// <summary>
// Builds validators based on the facets of <paramref name="edmProperty" />:
// * If .Nullable facet set to false adds a validator equivalent to the RequiredAttribute
// * If the .MaxLength facet is specified adds a validator equivalent to the MaxLengthAttribute.
// However the validator isn't added if .IsMaxLength has been set to true.
// </summary>
// <param name="clrProperty"> The CLR property to build the facet validators for. </param>
// <param name="edmProperty"> The property for which facet validators will be created </param>
// <returns> A collection of validators. </returns>
Builds validators based on the facets of :
If .Nullable facet set to false adds a validator equivalent to the RequiredAttribute
If the .MaxLength facet is specified adds a validator equivalent to the MaxLengthAttribute.
However the validator isn't added if .IsMaxLength has been set to true.
Builds validators based on the facets of : If . Nullable facet set to false adds a validator equivalent to the RequiredAttribute If the . MaxLength facet is specified adds a validator equivalent to the MaxLengthAttribute . However the validator isn ' t added if . IsMaxLength has been set to true .
protected virtual IEnumerable<IValidator> BuildFacetValidators(
            PropertyInfo clrProperty, EdmMember edmProperty, IEnumerable<Attribute> existingAttributes)
        {
            DebugCheck.NotNull(clrProperty);
            DebugCheck.NotNull(edmProperty);
            DebugCheck.NotNull(existingAttributes);
            var facetDerivedAttributes = new List<ValidationAttribute>();
            MetadataProperty storeGeneratedItem;
            edmProperty.MetadataProperties.TryGetValue(
                XmlConstants.AnnotationNamespace + ":" + XmlConstants.StoreGeneratedPattern,
                false,
                out storeGeneratedItem);
            var propertyIsStoreGenerated = storeGeneratedItem != null && storeGeneratedItem.Value != null;
            Facet nullable;
            edmProperty.TypeUsage.Facets.TryGetValue(EdmConstants.Nullable, false, out nullable);
            var nullableFacetIsFalse = nullable != null && nullable.Value != null && !(bool)nullable.Value;
            if (nullableFacetIsFalse
                && !propertyIsStoreGenerated
                && clrProperty.PropertyType.IsNullable()
                &&
                !existingAttributes.Any(a => a is RequiredAttribute))
            {
                facetDerivedAttributes.Add(
                    new RequiredAttribute
                        {
                            AllowEmptyStrings = true
                        });
            }
            Facet MaxLength;
            edmProperty.TypeUsage.Facets.TryGetValue(XmlConstants.MaxLengthElement, false, out MaxLength);
            if (MaxLength != null
                && MaxLength.Value != null
                && MaxLength.Value is int
                &&
                !existingAttributes.Any(a => a is MaxLengthAttribute)
                &&
                !existingAttributes.Any(a => a is StringLengthAttribute))
            {
                facetDerivedAttributes.Add(new MaxLengthAttribute((int)MaxLength.Value));
            }
            return from attribute in facetDerivedAttributes
                   select
                       new ValidationAttributeValidator(
                       attribute, existingAttributes.OfType<DisplayAttribute>().SingleOrDefault());
        }
protected virtual IEnumerable < IValidator > BuildFacetValidators ( PropertyInfo clrProperty , EdmMember edmProperty , IEnumerable < Attribute > existingAttributes ) { DebugCheck . NotNull ( clrProperty ) ; DebugCheck . NotNull ( edmProperty ) ; DebugCheck . NotNull ( existingAttributes ) ; var facetDerivedAttributes = new List < ValidationAttribute > ( ) ; MetadataProperty storeGeneratedItem ; edmProperty . MetadataProperties . TryGetValue ( XmlConstants . AnnotationNamespace + " " + XmlConstants . StoreGeneratedPattern , false , out storeGeneratedItem ) ; var propertyIsStoreGenerated = storeGeneratedItem != null && storeGeneratedItem . Value != null ; Facet nullable ; edmProperty . TypeUsage . Facets . TryGetValue ( EdmConstants . Nullable , false , out nullable ) ; var nullableFacetIsFalse = nullable != null && nullable . Value != null && ! ( bool ) nullable . Value ; if ( nullableFacetIsFalse && ! propertyIsStoreGenerated && clrProperty . PropertyType . IsNullable ( ) && ! existingAttributes . Any ( a => a is RequiredAttribute ) ) { facetDerivedAttributes . Add ( new RequiredAttribute { AllowEmptyStrings = true } ) ; } Facet MaxLength ; edmProperty . TypeUsage . Facets . TryGetValue ( XmlConstants . MaxLengthElement , false , out MaxLength ) ; if ( MaxLength != null && MaxLength . Value != null && MaxLength . Value is int && ! existingAttributes . Any ( a => a is MaxLengthAttribute ) && ! existingAttributes . Any ( a => a is StringLengthAttribute ) ) { facetDerivedAttributes . Add ( new MaxLengthAttribute ( ( int ) MaxLength . Value ) ) ; } return from attribute in facetDerivedAttributes select new ValidationAttributeValidator ( attribute , existingAttributes . OfType < DisplayAttribute > ( ) . SingleOrDefault ( ) ) ; }
Builds validators based on the facets of :
 If .Nullable facet set to false adds a validator equivalent to the RequiredAttribute
 If the .MaxLength facet is specified adds a validator equivalent to the MaxLengthAttribute.
Builds validators based on the facets of : If . Nullable facet set to false adds a validator equivalent to the RequiredAttribute If the . MaxLength facet is specified adds a validator equivalent to the MaxLengthAttribute .
A collection of validators.
A collection of validators .
clrProperty
PropertyInfo
The CLR property to build the facet validators for.
The CLR property to build the facet validators for .
edmProperty
EdmMember
The property for which facet validators will be created
The property for which facet validators will be created
existingAttributes
IEnumerable<Attribute>