title: Using metadata class to override EF field names in MVC view model not working
body: <p>I am writing an MVC5/EF6 web site, and I'm trying to keep the separation of data model and view models as complete as possible.</p>
  
  <p>So my EF classes (stored in a separate assembly) looks like this:</p>
  
  <pre><code>public class WorksOrder
  {
      [Key]
      public int Id { get; set; }
  
      public string CreatedById { get; set; }
  }
  </code></pre>
  
  <p>I have a metadata class in my view assembly (where the view controllers live) where I override the display name and add error messages</p>
  
  <pre><code>public class WorksOrder
  {
      [Display(Name = "Created by")]
      [Required(ErrorMessage = "created by cannot be blank")]
      public string CreatedById { get; set; }
  }
  </code></pre>
  
  <p>I attach the two classes in my view model with: </p>
  
  <pre><code>TypeDescriptor.AddProviderTransparent(
      new AssociatedMetadataTypeTypeDescriptionProvider(typeof(EF.Models.WorksOrder),
      typeof(ViewMetadata.WorksOrder)), typeof(EF.Models.WorksOrder));
  </code></pre>
  
  <p>When I display the form, the field label is "CreatedById" rather than the display attribute ("Created by") specified in the metadata class.   I know the AddProviderTransparent has worked because if I try to submit a form with the CreatedById field empty, I get the error message ("created by cannot be blank").</p>
  
  <p><strong>Edit</strong>: This is the Razor file (I've cleaned out the unimportant stuff (divs etc).</p>
  
  <pre><code>@model App.Models.WorksOrderCreateModel
  
  @using (Html.BeginForm())
  {
      @Html.LabelFor(model =&gt; model.WorksOrder.CreatedById, new { @class = "control-label col-md-3" })
      @Html.TextBoxFor(model =&gt; model.WorksOrder.CreatedById, new { @class = "form-control col-md-3" })
      @Html.ValidationMessageFor(model =&gt; model.WorksOrder.CreatedById)
  </code></pre>