While there are more ways to trigger validations, let’s stick with
GetValidationResult method while we
look at other ways to provide rules that the Validation API will validate.
So far you’ve seen how to apply validation rules on individual properties.
You can also define rules for a type that can take multiple properties
into account. Two ways to create type-level validation that will be
checked by the Entity Framework Validation API are by having your type
interface or defining
CustomValidationAttributes for type. This
section will explore both of these options.
In addition to the
ValidationAttribute, .NET 4 introduced another
feature to help developers with validation logic—the
IValidatableObject provides a
Validate method to let developers (or
frameworks) provide their own context from which to perform the
If an entity that is being validated implements the
IValidatableObject interface, the Validation
API logic will recognize this, call the Validate method, and surface the
results of the validation in a
provide that is not satisfied with Data Annotations? The Data
Annotations let you specify a limited number of rules for individual
properties. With the additional
Validate method, you can provide any type of logic that can be constrained to the class. What we mean by ...