I'm looking on this documentation example. It's looks like useful. For rxample I have the following view-model:
class CustomerViewModel
{
public string Name {get; set;}
public List<int> Roles {get; set;}
}
I would like to check if all Roles exist in my database. I'm trying something like:
class CustomerViewModel : IValidatableObject
{
public string Name {get; set;}
public List<int> Roles {get; set;}
public async Task<IEnumerable<ValidationResult>> Validate(ValidationContext validationContext)
{
await Task.Delay(123); /// imagine that it's database call
// and so on
}
}
And surprise! It's impossible. It does not work. Because there is no async version of Validate(
Is it possible to validate my model in model? Or I have to write separate validation services?