title: Using System.ComponentModel.DataAnnotations with Entity Framework 4.0
body: <p>I'm working with MVC3, and using Entity Framework 4.0 Entities as my model.  So far, everything works great as far as using it as a model (all the crud operations/page generations work out of the box).  I'm wondering, though, how do you get the same robust labels and validation information as when you generate a model manually?</p>
  
  <p>Here's an example of what I mean. This is a class generated by the sample MVC3 project:</p>
  
  <pre><code>public class LogOnModel
  {
      [Required]
      [Display(Name = "User name")]
      public string UserName { get; set; }
  
      [Required]
      [DataType(DataType.Password)]
      [Display(Name = "Password")]
      public string Password { get; set; }
  
      [Display(Name = "Remember me?")]
      public bool RememberMe { get; set; }
  }
  </code></pre>
  
  <p>With the example above, you can specify what gets rendered in a label for the field (Display), and what type of field to use (Password).  However, when I try to use the entity framework and push it to the view below, I see the automatically generated labels are just the field names, and not anything I want the user to see/have to read:</p>
  
  <pre><code>@using (Html.BeginForm()) {
      @Html.ValidationSummary(true)
      &lt;fieldset&gt;
          &lt;legend&gt;Person&lt;/legend&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.FirstName)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.FirstName)
              @Html.ValidationMessageFor(model =&gt; model.FirstName)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.MiddleName)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.MiddleName)
              @Html.ValidationMessageFor(model =&gt; model.MiddleName)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.LastName)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.LastName)
              @Html.ValidationMessageFor(model =&gt; model.LastName)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.Birthdate)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.Birthdate)
              @Html.ValidationMessageFor(model =&gt; model.Birthdate)
          &lt;/div&gt;
  
          &lt;p&gt;
              &lt;input type="submit" value="Create" /&gt;
          &lt;/p&gt;
      &lt;/fieldset&gt;}
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/N6ZbE.png" alt="enter image description here"></p>
  
  <p><strong>My question is:</strong> How do I add these extra decorations to the entities that are generated using EF4?  Is there something besides System.ComponentModel.DataAnnotations that I should be using? I know entities get regenerated and it's probably not a good idea to add this to entities' code directly, but for some reason I can't think of a better approach than manually entering the label text in the view (lame, there's no reason to have to do that, this is MVC!).  I want to keep it so that the application is dynamic enough to be able to have the correct display information for my model come through and keep an MVC approach.  How do I do it?</p>