For example, I have a validator with two validation rules:
RuleFor(o => o.Email).Must((email) => this.GetDataDataFromDB(email) != 0)
.WithMessage("User with provided Email was not found in database!");
RuleFor(o => o.Email).Must((email) => this.GetDataDataFromDB(email) >= 1)
.WithMessage("There are multiple users with provided Email in database!");
As you can see, there are two database calls with the same method. How can I call him once and reuse data for other rules?
Another issue when displaying error messages:
RuleFor(o => o.Email).Must((email) => this.GetDataDataFromDB(email) >= 1)
.WithMessage("There are multiple users with following Email '{0}' in database!",
(model, email) => { return email; });
Is there a better way to display error messages that don't write these lambda expressions all the time to retrieve the property? How and where to save the model, and then use it later.
Simple and easy to use solutions would be nice!
Edgar source
share