I am trying to use fluentvalidation to validate pin to ensure what user type match with existing pin. AppDbContext is the context class which inherit from dbcontext (Entity Framework). I have this syntax error while calling isOldPin method. If PinCodeOld datatype is string, this error doesn't appear. But if PinCodeOld datatype is long, this error appear.
public class ChangePinValidator : AbstractValidator<VMPinChange>
{
private readonly AppDbContext db = new AppDbContext();
public ChangePinValidator()
{
RuleFor(b => b.PinCodeOld).Must(isOldPin).WithMessage("Invalid current pin code.");
RuleFor(b => b.PinCodeNew).Equal(b => b.PinCodeConfirmation)
.WithMessage("New pin code is not same with confirmed new pin code.");
}
private bool isOldPin(string _currentPin)
{
bool isMatch = db.BankAccounts.Any(b => b.PinCode.Equals(_currentPin));
return isMatch;
}
}
The problem is this:
RuleFor(b => b.PinCodeOld).Must(isOldPin)
If PinCodeOld
is a long, then the Must
method is going to expect a method that takes a long
value as input, but your method takes a string
. If you need it to be long
then you also need to change the isOldPin
to take a long
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.