title: Using DataAnnotations with Entity Framework
body: <p>I have used the Entity Framework with VS2010 to create a simple person class with properties, firstName, lastName, and email.  If I want to attach DataAnnotations like as is done in this <a href="http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx" rel="noreferrer">blog post</a> I have a small problem because my person class is dynamically generated.  I could edit the dynamically generated code directly but any time I have to update my model all my validation code would get wiped out.</p>
  
  <p>First instinct was to create a partial class and try to attach annotations but it complains that I'm trying to redefine the property.  I'm not sure if you can make property declarations in C# like function declarations in C++.  If you could that might be the answer.  Here's a snippet of what I tried:</p>
  
  <pre><code>namespace PersonWeb.Models
  {
    public partial class Person
    {
      [RegularExpression(@"(\w|\.)+@(\w|\.)+", ErrorMessage = "Email is invalid")]
      public string Email { get; set; } 
      /* ERROR: The type 'Person' already contains a definition for 'Email' */
    }
  }
  </code></pre>