Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validating collections with FluentValidation

I am trying to do something like this :

RuleFor(client => client.PriceCustomization.GroupBy(a=>a.ProductId).Select(a => a.ToList()))
   .SetCollectionValidator(new PriceCustomizationsForProductValidator());

But I am receiving this error : Failed: System.InvalidOperationException : Nested validators can only be used with Member Expressions.

"PriceCustomizationsForProductValidator" is a validator for a List of "PriceCustomization"

Does anyone have any idea how could I solve this?

like image 663
Daniel Barbulescu Avatar asked Oct 18 '25 08:10

Daniel Barbulescu


1 Answers

Using FluentValidation version 8, try this:

RuleForEach(client => client.PriceCustomization)
   .SetValidator(new PriceCustomizationsForProductValidator());

See https://fluentvalidation.net/upgrading-to-8.html

like image 115
George Paoli Avatar answered Oct 20 '25 00:10

George Paoli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!