问题类似于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();
});
}
}
答案 0 :(得分:1)
好的,应该使用Items.NotEmpty()而不是NotNull()。