diff --git a/src/OpenRiaServices.Client/Framework/Entity.cs b/src/OpenRiaServices.Client/Framework/Entity.cs index d0da50e23..8757f4f3a 100644 --- a/src/OpenRiaServices.Client/Framework/Entity.cs +++ b/src/OpenRiaServices.Client/Framework/Entity.cs @@ -1309,6 +1309,12 @@ protected void ValidateProperty(string propertyName, object value) validationContext.MemberName = propertyName; this.ValidateProperty(validationContext, value); } + else if (MetaType.RequiresObjectValidation) + { + // Validation error must have been set by object level validation + // Clear it to mimic old behaviour where validate property was always called in these scenarios + this.ValidationResultCollection.ReplaceErrors(propertyName, Array.Empty()); + } } /// diff --git a/src/OpenRiaServices.Client/Framework/Internal/MetaType.cs b/src/OpenRiaServices.Client/Framework/Internal/MetaType.cs index 8100e5c25..31914d516 100644 --- a/src/OpenRiaServices.Client/Framework/Internal/MetaType.cs +++ b/src/OpenRiaServices.Client/Framework/Internal/MetaType.cs @@ -32,6 +32,7 @@ public sealed class MetaType [ThreadStatic] private static Dictionary s_metaTypes; private readonly bool _requiresValidation; + private readonly bool _requiresObjectValidation; private readonly Type[] _childTypes; private readonly Dictionary _metaMembers = new Dictionary(); private readonly ReadOnlyCollection _dataMembers; @@ -121,7 +122,8 @@ select attribute this.Type = type; _validationAttributes = new ReadOnlyCollection(this.Type.GetCustomAttributes(typeof(ValidationAttribute), true).OfType().ToArray()); - _requiresValidation = _requiresValidation || _validationAttributes.Any() || typeof(IValidatableObject).IsAssignableFrom(type); + _requiresObjectValidation = _validationAttributes.Any() || typeof(IValidatableObject).IsAssignableFrom(type); + _requiresValidation = _requiresValidation || _requiresObjectValidation; // for identity purposes, we need to make sure values are always ordered KeyMembers = new ReadOnlyCollection(_metaMembers.Values.Where(m => m.IsKeyMember).OrderBy(m => m.Name).ToArray()); @@ -262,6 +264,12 @@ public IEnumerable AssociationMembers /// public bool RequiresValidation => this._requiresValidation; + /// + /// Gets a value indicating whether the Type requires any Type level + /// validation. + /// + internal bool RequiresObjectValidation => this._requiresObjectValidation; + /// /// Gets a value indicating whether the Type has any members marked with /// CompositionAttribute.