How to code rules with more than 1 property in it?

Feb 20, 2010 at 11:04 AM
Edited Feb 20, 2010 at 11:20 AM

How would i code a rule like this?

RuleFor( d => (d.Vak01+d.Vak02+d.Vak03 > 0M ) &&  (d.Vak54 == 0M) ).NotEqual(true)



It seems the extra property name is not important here ??

If i use an empty string, the rule does work.

RuleFor( "" , d => (d.Vak01+d.Vak02+d.Vak03 > 0M ) &&  (d.Vak54 == 0M) ).NotEqual(true)



Apr 13, 2010 at 1:11 PM
Edited Apr 13, 2010 at 1:18 PM

The extra property name is only used for injecting into validation error messages. In FluentValidation for .NET 3.5 this is done by compiling the Expression to get the property name. However, because Expressions are not available in .NET 2.0, this rework requires a string. I made it possible to enter an empty string but if you want useful validation messages, I would recommen you include the property name. In the example that you have given, I would recommend writing a custom Validator.

Custom(d => {
if (d.Vak01+d.Vak02+d.Vak03 <= 0M) return new ValidationFailure("Vak01", "Put your custom error message here");
if (... other test ...)
return new ValidationFailure("Property Name", "Put your next custom error message here"); return null; }