0

I have model

public class DocProperty
{
    public int Size {get; set;}
    public int Volume {get; set;}
    ...
}

and I'm using FluentValidation

public class DocPropertyValidator: AbstractValidator<DocProperty>    
{
    public DocPropertyValidator()
    {
        RuleFor(a => a.Size).Must(x => x < 1).WithMessage("Invalid Size!");
        RuleFor(a => a.Volume ).Must(x => x < 1).WithMessage("Invalid Volume!");            
    }
}

My question is: How can I use FluentValidation and validate case when Volume < Size.

In this case print Invalid case, volume cannot be less then Size.

user1765862
  • 13,635
  • 28
  • 115
  • 220
  • 1
    Does this answer your question? [FluentValidation rule for multiple properties](https://stackoverflow.com/questions/20529085/fluentvalidation-rule-for-multiple-properties) – Th0rndike Aug 25 '21 at 15:46
  • `RuleFor(a => a.Volume).Must((dp, vol) => vol >= dp.Size).WithMessage("Volume cannot be less then Size")`; – Fildor Aug 25 '21 at 15:51

0 Answers0