O'Reilly logo

Fluent Entity Framework by Rebecca M. Riordan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Ivalidatable object

Custom validation attributes are convenient if you want to reuse validation code for multiple properties. They can even be used for type-level validation (which doesn’t make sense for the other validation attributes). But the DbContext also offers an alternative: the IValidatableObject interface, which can be implemented on your classes.

The IValidatableObject interface has a single method, Validate(), which takes a ValidationObject parameter and returns an IEnumerable<ValidationError> result:

Image

public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)

Public Function Validate(ByVal validationContext ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required