1

Closed

OverridePropertyName is ignored in ValidationResult.PropertyName path when used with SetValidator and SetCollectionValidator

description

ValidationResult.PropertyName is generally affected by .OverridePropertyName, except when used with a navigation property with a sub-validator set. In these cases, the first portion of the ValidationResult.PropertyName path still matches the navigation property name, indexed in the case of a collection.

For example:
RuleFor(ow => ow.FineComponentCollection)
    .Must((ow, coll) => coll.Any(fc => fc.Amount > 0))
    .When(ow => ow.FineComponentCollection.Count > 0)
    .OverridePropertyName("Test") // this works
    .WithMessage("At least one non-zero monetary amount must be specified.");

RuleFor(ow => ow.FineComponentCollection)
    .SetCollectionValidator(OutcomeFineComponentValidator.GetValidator(isNewEntity))
    .OverridePropertyName("Test"); // this doesn't work
In the latter case, my ValidationResult.PropertyName still ends up as something like "FineComponentCollection[2].Amount" instead of "Test[2].Amount".
Closed Apr 23, 2013 at 1:14 PM by JeremyS

comments

JeremyS wrote Mar 14, 2013 at 9:18 AM

Thanks for reporting this, I've fixed it in the latest commit.