Skip to content

Commit

Permalink
Add possible fix for regression
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-Svensson committed Nov 1, 2023
1 parent fec6dd2 commit 83f3996
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/OpenRiaServices.Client/Framework/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ValidationResult>());
}
}

/// <summary>
Expand Down
10 changes: 9 additions & 1 deletion src/OpenRiaServices.Client/Framework/Internal/MetaType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public sealed class MetaType
[ThreadStatic]
private static Dictionary<Type, MetaType> s_metaTypes;
private readonly bool _requiresValidation;
private readonly bool _requiresObjectValidation;
private readonly Type[] _childTypes;
private readonly Dictionary<string, MetaMember> _metaMembers = new Dictionary<string, MetaMember>();
private readonly ReadOnlyCollection<MetaMember> _dataMembers;
Expand Down Expand Up @@ -121,7 +122,8 @@ select attribute
this.Type = type;

_validationAttributes = new ReadOnlyCollection<ValidationAttribute>(this.Type.GetCustomAttributes(typeof(ValidationAttribute), true).OfType<ValidationAttribute>().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<MetaMember>(_metaMembers.Values.Where(m => m.IsKeyMember).OrderBy(m => m.Name).ToArray());
Expand Down Expand Up @@ -262,6 +264,12 @@ public IEnumerable<MetaMember> AssociationMembers
/// </summary>
public bool RequiresValidation => this._requiresValidation;

/// <summary>
/// Gets a value indicating whether the Type requires any Type level
/// validation.
/// </summary>
internal bool RequiresObjectValidation => this._requiresObjectValidation;

/// <summary>
/// Gets a value indicating whether the Type has any members marked with
/// CompositionAttribute.
Expand Down

0 comments on commit 83f3996

Please sign in to comment.