Reputation: 701
How do I write the validation rule if I want to check if at least one of the properties in the request DTO is not empty?
I can do it individually, but I can't seem to figure out how to combine multiple to do something like - check if at least one of FirstName, LastName and CompanyName has a value.
Upvotes: 1
Views: 201
Reputation: 143389
This is a Fluent Validation question, you can use When()
to selectively apply the rule, e.g:
RuleFor(x => x.FirstName)
.NotEmpty()
.When(x => (x.LastName ?? x.CompanyName).IsNullOrEmpty());
Upvotes: 4