/// <summary> /// Creates <see cref="EntityValidationContext" /> for <paramref name="entityEntry" />. /// </summary> /// <param name="entityEntry"> Entity entry for which a validation context needs to be created. </param> /// <param name="items"> User defined dictionary containing additional info for custom validation. This parameter is optional and can be null. </param> /// <returns> /// An instance of <see cref="EntityValidationContext" /> class. /// </returns> /// <seealso cref="DbContext.ValidateEntity" /> public virtual EntityValidationContext GetEntityValidationContext( InternalValidateEntity entityEntry, IDictionary <object, object> items) { DebugCheck.NotNull(entityEntry); return(new EntityValidationContext(entityEntry, new ValidationContext(entityEntry.EntityValue, null, items))); }
/// <summary> /// Initializes a new instance of EntityValidationContext class. /// </summary> /// <param name="entityEntry"> The entity being validated or the entity that owns the property being validated. </param> /// <param name="externalValidationContext"> External context needed for validation. </param> public EntityValidationContext(InternalValidateEntity entityEntry, ValidationContext externalValidationContext) { DebugCheck.NotNull(entityEntry); DebugCheck.NotNull(externalValidationContext); _entityEntry = entityEntry; ExternalValidationContext = externalValidationContext; }
/// <summary> /// Builds an <see cref="EntityValidator" /> for the given <paramref name="entityEntry" />. /// </summary> /// <param name="entityEntry"> The entity entry to build the validator for. </param> /// <returns> /// <see cref="EntityValidator" /> for the given <paramref name="entityEntry" /> . Possibly null if no validation has been specified for this entity type. /// </returns> public virtual EntityValidator BuildEntityValidator(InternalValidateEntity entityEntry) { DebugCheck.NotNull(entityEntry); return(BuildTypeValidator( entityEntry.EntityType, entityEntry.NavigationProperties, (propertyValidators, typeLevelValidators) => new EntityValidator(propertyValidators, typeLevelValidators))); }
public virtual PropertyValidator GetPropertyValidator( InternalValidateEntity owningEntity, InternalValidateProperty property) { DebugCheck.NotNull(owningEntity); DebugCheck.NotNull(property); var entityValidator = GetEntityValidator(owningEntity); return(entityValidator != null?GetValidatorForProperty(entityValidator, property) : null); }
/// <summary> /// Returns a validator to validate <paramref name="entityEntry" />. /// </summary> /// <param name="entityEntry"> Entity the validator is requested for. </param> /// <returns> /// <see cref="EntityValidator" /> to validate <paramref name="entityEntry" /> . Possibly null if no validation has been specified for the entity. /// </returns> public virtual EntityValidator GetEntityValidator(InternalValidateEntity entityEntry) { DebugCheck.NotNull(entityEntry); var entityType = entityEntry.EntityType; EntityValidator validator = null; if (entityType == null) { return(validator); } if (_entityValidators.TryGetValue(entityType, out validator)) { return(validator); } else { validator = _entityValidatorBuilder.BuildEntityValidator(entityEntry); _entityValidators[entityType] = validator; return(validator); } }
public InternalValidateProperty(System.Reflection.PropertyInfo propertyInfo, InternalValidateEntity instance) { this._propertyInfo = propertyInfo; this._instance = instance; }