FluentValidation - 未验证内部集合

时间:2016-02-09 10:03:26

标签: c# fluentvalidation

问题类似于FluentValidation collection properties not validated,遗憾的是他们的修复无效。任何想法为什么没有涉及基础OrderValidator?

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();
        });
    }
}

1 个答案:

答案 0 :(得分:1)

好的,应该使用Items.NotEmpty()而不是NotNull()。