Best Practices - Data Annotations vs OnChanging in Entity Framework 4

Posted by jptacek on Stack Overflow See other posts from Stack Overflow or by jptacek
Published on 2010-05-04T02:24:20Z Indexed on 2010/05/04 2:28 UTC
Read the original article Hit count: 587

I was wondering what the general recommendation is for Entity Framework in terms of data validation. I am relatively new to EF, but it appears there are two main approaches to data validation.

The first is to create a partial class for the model, and then perform data validations and update a rule violation collection of some sort. This is outlined at http://msdn.microsoft.com/en-us/library/cc716747.aspx

The other is to use data annotations and then have the annotations perform data validation. Scott Guthrie explains this on his blog at http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx.

I was wondering what the benefits are of one over the other. It seems the data annotations would be the preferred mechanism, especially as you move to RIA Services, but I want to ensure I am not missing something. Of course, nothing precludes using both of them together.

Thanks

John

© Stack Overflow or respective owner

Related posts about entity-framework

Related posts about dataannotations