title: Validate complex types with DataAnnotations
body: <p>I've decided to use Entity Framework for O/R Mapping, and DataAnnotations for validation in my project, and I have now encountered an odd problem when trying to implement this.</p>
  
  <p>This is what I've done:</p>
  
  <p>I have the following entity type</p>
  
  <pre><code>Contact
  *******
  Int32 Id (not null, Entity Key)
  Name Name (not null) 
  Address Address (not null)
  String Phone
  String Email
  </code></pre>
  
  <p>where <code>Name</code> and <code>Address</code> are complex types defined as follows:</p>
  
  <pre><code>Name                                  Address
  ****                                  *******
  String First (not null)               String Street (not null)
  String Last (not null)                String ZipCode (not null)
                                        String City (not null)
  </code></pre>
  
  <p>And the following classes reside in the same namespace as my entities:</p>
  
  <pre><code>public class ContactMetadata
  {
      [Required]
      public Name Name { get; set; }
  }
  
  [MetadataType(typeof(ContactMetadata))]
  partial class Contact { }
  </code></pre>
  
  <p>However, when I create a new <code>Contact</code> item, the <code>Name</code> and <code>Address</code> types are filled with instances of <code>Name</code> and <code>Address</code> where all values are <code>null</code>, instead of <code>Name</code> and <code>Address</code> having <code>null</code> values themselves. Thus, the <code>Required</code> attribute doesn't throw any errors, although all values are <code>null</code>. How do I work around this?</p>