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

Creating custom attributes

Writing a custom validation annotation is easier than you might expect. It’s just a static method with a specific signature. It doesn’t have to extend ValidationAttribute, and can even live in the same class definition as the entity it validates. Here are some examples:

Image

To use the custom method, you pass the class in which it’s declared and the method name to the CustomValidation attribute:

Image

[CustomValidation(typeof(MyClass), "myValidator")]

<CustomValidation(typeof(MyClass), "myValidator")>

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