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

New Post: Unique Value Validation

$
0
0
Jeremy provided the answer by posting the following link'

http://fluentvalidation.codeplex.com/wikipage?title=Validators&referringTitle=Documentation&ANCHOR#Predicate

If you read the SECOND section of this part of the documentation you will see;

Note that there is an additional overload for Must that also accepts an instance of the parent object being validated. This can be useful if you want to compare the current property with another property from inside the predicate:

Example.
RuleFor(customer => customer.Surname).Must((customer, surname) => surname != customer.Forename)

As you can see the customer entity is passed into the .Must() method as a parameter and is therefore available to the predicate.

So I did not need to create a separate custom validator, I could use an existing method to achieve the validation I required.

Viewing all articles
Browse latest Browse all 1917

Trending Articles



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