avj
avj

Reputation: 1686

FluentValidation - inner collection not validated

Have problem similar to FluentValidation collection properties not validated, unfortunately their fix does not work. Any ideas why underlying OrderValidator is not being involved?

validator.Validate(client, ruleSet: "Production");

public class ClientValidator : AbstractValidator<Client>
{
    public ClientValidator()
    {
        RuleSet("Production", () =>
        {
            RuleFor(client => client.Orders)
                .NotEmpty();

            RuleFor(client => client.Orders)
                .SetCollectionValidator(new OrderValidator());
        });
    }
}

public class OrderValidator : AbstractValidator<Order>
{
    public OrderValidator()
    {
        RuleSet("Production", () =>
        {
            RuleFor(x => x.Items)
                .NotNull();
        });
    }
}

Upvotes: 2

Views: 176

Answers (1)

avj
avj

Reputation: 1686

Ok, Items.NotEmpty() should have been used instead of NotNull().

Upvotes: 1

Related Questions