title: How to correctly use a viewmodel
body: <p>I am new to ASP.net MVC.  I am trying to create a viewmodel to display a join of data.  Here is some example code:</p>
  
  <pre><code>   public class Person
  {
      [Key]
      public int ID { get; set; }
      public string Name { get; set; }
  
      public ICollection&lt;Relative&gt; Relatives { get; set; }
  
  }
  
  public class Relative
  {
      [Key]
      public int ID {get; set; }
      public Person Person { get; set; }
      public RelationType RelationType { get; set; }
  }
  
  public class RelationType
  {
      [Key]
      public int ID { get; set; }
      public string Description { get; set; }
  }
  
  public class PersonViewModel
  {
      public string Name { get; set; }
      public ICollection&lt;string&gt; RelativeNames { get; set; }
      public ICollection&lt;string&gt; RelativeTypes { get; set; }
  }
  
  public class PersonContext : DbContext
  {
      public DbSet&lt;PersonViewModel&gt; people { get; set; }
  }
  </code></pre>
  
  <p>When I try to create my controller through Visual Studio, I get the following error:</p>
  
  <p>Unable to retrieve metadata for PersonViewModel. One or more validations errors were detected during generation:
  EntityType 'PersonViewModel' has no key defined.  Define the key for this EntityType.</p>