title: How To Scaffold a View Model in MVC 5
body: <p>I'm trying to work on a simple application.
  I have three SQL tables brought in through Entity Framework and had the models created automatically.
  I want to be able to scaffold out the Create/Details/Edit etc. views automatically in Visual Studio.  I can do this automatically when I scaffold from a single model (like Name alone), but can't get anywhere when using a View Model as a source.</p>
  
  <p>Here are my models</p>
  
  <p>Name</p>
  
  <pre><code>public partial class Name
  {
      public Name()
      {
          this.Addresses = new HashSet&lt;Address&gt;();
          this.Emails = new HashSet&lt;Email&gt;();
      }
  
      public int ID { get; set; }
      public string FIRST_NAME { get; set; }
      public string LAST_NAME { get; set; }
  
      public virtual ICollection&lt;Address&gt; Addresses { get; set; }
      public virtual ICollection&lt;Email&gt; Emails { get; set; }
  }
  </code></pre>
  
  <p>Address</p>
  
  <pre><code>public partial class Address
  {
      public int ADDRESS_ID { get; set; }
      public int NameID { get; set; }
      public string ADDRESS_1 { get; set; }
      public string CITY { get; set; }
      public string STATE { get; set; }
      public string ZIP { get; set; }
  
      public virtual Name Name { get; set; }
  }
  </code></pre>
  
  <p>Email</p>
  
  <pre><code>public partial class Email
  {
      public int EMAIL_ID { get; set; }
      public int NameID { get; set; }
      public string EMAIL { get; set; }
  
      public virtual Name Name { get; set; }
  }
  </code></pre>
  
  <p>and a View Model I created of all three</p>
  
  <pre><code>public class MainVM
  {
      public Name Name { get; set; }
      public Address Address { get; set; }
      public Email Email { get; set; }
  }
  </code></pre>
  
  <p>I can go through the steps of creating a controller - 
  Right click Controllers >> Add >> Controller >> MVC 5 Controller with views, using Entity Framework.</p>
  
  <p>Next I get to this screen.</p>
  
  <p><img src="https://i.stack.imgur.com/1MRWv.png" alt="enter image description here"></p>
  
  <p>If I click Add, I will get the following error.</p>
  
  <p><img src="https://i.stack.imgur.com/MmE9b.png" alt="enter image description here"></p>
  
  <p>I've read in other answers that you need to clear out the Data context class (from the first image) if you are using a View Model, but if I do that, the Add button becomes deactivated.  I can't go further than that.
  Any ideas here?</p>