EF Code First (starting with CTP5) now has built-in support
for both DataAnnotations and the IValidatableObject interface. This
allows you to easily add validation and business rules to your models, and have
EF automatically ensure that they are enforced anytime someone tries to persist
changes of them to a database.
ASP.NET MVC 3 also now supports both DataAnnotations and
IValidatableObject as well, which makes it even easier to use them with your EF
Code First model layer – and then have the controllers/views within your web
layer automatically honor and support them as well. This makes it easy to
build clean and highly maintainable applications.
You don’t have to use DataAnnotations or IValidatableObject
to perform your validation/business logic. You can always roll your own
custom validation architecture and/or use other more advanced validation
frameworks/patterns if you want. But for a lot of applications this
built-in support will probably be sufficient – and provide a highly productive
way to build solutions.
Hope this helps,
Scott
P.S. In addition to blogging, I am also now using Twitter
for quick updates and to share links. Follow me at: twitter.com/scottgu