Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

New Post: Understanding dependent rules

$
0
0
Dear Jeremy,

I have been reading about dependent rules here:

https://github.com/JeremySkinner/FluentValidation/issues/65

From my understanding, a dependent rule will execute only if the preceding rules succeed. However, I cannot get this to work. Ex:

RuleFor(o => o).NotNull().WithMessage("Customer cannot be null")
.DependentRules(d =>
{
 d.RuleFor(x => x.FirstName).NotEmpty().WithMessage("First name cannot be empty");

 // Other code to execute here
});

If I pass in a customer object which is not null, I expect to validate the first name. However, no validation is fired. What am I doing wrong or what am I missing here?

Thank you for your help,

Michael

Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>