.NET FluentValidation: Parent rule depending on child value

173 Views Asked by At

I tried in this way but this doesn´t work properly:

RuleForEach(p => p.Childs).NotEmpty().ChildRules(child =>
        {
            child.RuleFor(p => p.Name).NotEmpty();
            When(p => p.Child2.Name == "cool", () =>
            {
                child.When(c => c.Code < 56, () =>
                {
                    RuleFor(p => p.Surname).NotEmpty();
                    When(p => p.Date.HasValue, () =>
                    {
                        RuleFor(p => p.Total).InclusiveBetween(4, 6);
                    });
                });
            });
        });

Could anyone helps me? Thx

0

There are 0 best solutions below