Below is a simplified version of my problem.
I can not flatten the model. There is a List of \"children\" that I need to validate a birthday.
I can not seem
There is a way easier way to do this using set child validator:
public class ChildValidator : AbstractValidator
{
public ChildValidator(Parent parent)
{
RuleFor(model => model.ChildProperty).NotEmpty();
RuleFor(model => model.Birthday).Must(birthday => parent.Birthday > birthday);
}
}
public class ParentValidator : AbstractValidator
{
public ParentValidator()
{
RuleFor(model => model.Name).NotEmpty();
}
public override ValidationResult Validate(Parent parent)
{
RuleFor(model => model.Children).SetCollectionValidator(new ChildValidator(this));
return base.Validate();
}
}