0

In EF Core, there is a neat way to perform entity validation using IValidatableObject.

During validation I have the current value, but I also need access to the original value.

This is the validation method:

public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { }

Is there some way to get access to the object's original values as well? I think the key is in ValidationContext but I'm not sure how.

Community
  • 1
  • 1
grokky
  • 8,537
  • 20
  • 62
  • 96
  • 1
    You can gain access to the context if you want: http://stackoverflow.com/a/31527559/861716 – Gert Arnold Jan 20 '17 at 20:36
  • @Gert Thanks, I suppose that is one way. However It's probably not the "cleanest" way to do this - the entity shouldn't have access to all that power. I hope it's possible to find the original values some other way. The `ValidationContext` has some kind of service object overload, but I'm not yet sure how to use it. – grokky Jan 20 '17 at 21:14

0 Answers0