title: Trying to scaffold a view and I get "unable to retrieve Metadata for" and 'validation error' 'entity type has no key defined'
body: <p>I have a program where I am trying to figure out an issue that my friends are not getting. I am trying to scaffold a view from my controller, and I get an </p>
  
  <pre><code>error "Unable to retrieve metadata for 'GradedWork.Controllers.CourseAddForm'. 
  One or more validation errors were detected during model generation: 
  
  GradedWork.Model.CourseAddForm : EntityType 'CourseAddForm' has no key defined. Define the 
  key for this EntityType. CourseAddForm: EntityType: EntitySet 'CourseAddForm' is based on 
  type 'CourseAddForm' that has no keys defined.'
  </code></pre>
  
  <p>I am trying to scaffold a create view using the CourseAddForm view model class but I always get this error.</p>
  
  <p>My CourseAddForm class is not supposed to carry a key field, my friends do not have this problem that I am having.</p>
  
  <p>My view model class:</p>
  
  <pre><code>namespace GradedWork.Controllers
  {
  public class CourseList
  {
      [Key]
      public int Id { get; set; }
  
      [Display(Name = "Name")]
      public string Name { get; set; }
  
  }
  
  public class CourseAddForm
  {
  
  
      [Display(Name = "Course Code")]
      public int CourseCode { get; set; }
  
      // [Required]
      [Display(Name = "Name")]
      public string Name { get; set; }
  
      //  [Required]
      [Display(Name = "Semester")]
      public string Semester { get; set; }
  
      // [Required]
      [Display(Name = "Section Id")]
      public string SectionId { get; set; }
  
      [Display(Name = "Teacher")]
      public ICollection&lt;TeacherList&gt; Teacher { get; set; }
  
      [Display(Name = "Student")]
      public ICollection&lt;StudentList&gt; Students { get; set; }
  
      [Display(Name = "Graded Works")]
      public ICollection&lt;GradedWorkList&gt; GradedWorks { get; set; }
  
  
      public CourseAddForm()
      {
          this.Teacher = new List&lt;TeacherList&gt;();
          this.Students = new List&lt;StudentList&gt;();
          this.GradedWorks = new List&lt;GradedWorkList&gt;();
  
      }
  
  }
  
  public class CourseAdd
  {
  
      [Display(Name = "Course Code")]
      public int CourseCode { get; set; }
  
      // [Required]
      [Display(Name = "Name")]
      public string Name { get; set; }
  
      //  [Required]
      [Display(Name = "Semester")]
      public string Semester { get; set; }
  
      // [Required]
      [Display(Name = "Section Id")]
      public string SectionId { get; set; }
  
      [Display(Name = "Teacher")]
      public ICollection&lt;Teacher&gt; Teacher { get; set; }
  
      [Display(Name = "Student")]
      public ICollection&lt;Student&gt; Students { get; set; }
  
      [Display(Name = "Graded Works")]
      public ICollection&lt;GradedWorks&gt; GradedWorks { get; set; }
  
  
      public CourseAdd()
      {
          this.Teacher = new List&lt;Teacher&gt;();
          this.Students = new List&lt;Student&gt;();
          this.GradedWorks = new List&lt;GradedWorks&gt;();
  
      }
  
  }
  
  public class CourseBase : CourseAdd
  {
      [Key]
      public int Id { get; set; }
  
  }
  }
  </code></pre>
  
  <p>My controller method that I am trying to scaffold</p>
  
  <pre><code>public ActionResult Create()
      {
          var addForm = new CourseAddForm();
  
          foreach (var item in m.GetAllTeachersAsList())
          {
              addForm.Teacher.Add(item);
          }
  
          foreach (var item in m.GetAllStudentsAsList())
          {
              addForm.Students.Add(item);
          }
  
          foreach (var item in m.GetAllGradedWorkAsList())
          {
              addForm.GradedWorks.Add(item);
          }
  
          return View(addForm);
      }
  
      //
      // POST: /Course/Create
      [HttpPost]
      public ActionResult Create(CourseAdd newItem)
      {
          if (ModelState.IsValid)
          {
  
              var addedItem = m.AddCourse(newItem);
  
              if (addedItem == null)
              {
                  return RedirectToAction("Index");
              }
  
              else
              {
                  return RedirectToAction("Details", new { id = addedItem.Id });
              }
  
  
          }
  
          else
          {
              var addForm = Mapper.Map&lt;CourseAddForm&gt;(newItem);
  
              foreach (var item in m.GetAllTeachersAsList())
              {
                  addForm.Teacher.Add(item);
              }
  
              foreach (var item in m.GetAllStudentsAsList())
              {
                  addForm.Students.Add(item);
              }
  
              foreach (var item in m.GetAllGradedWorkAsList())
              {
                  addForm.GradedWorks.Add(item);
              }
  
              return View(addForm);
          }
      }
  </code></pre>
  
  <p>My connection string:</p>
  
  <pre><code>&lt;connectionStrings&gt;
  &lt;add name="DataContext" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\StoreName.mdf;Initial Catalog=StoreName;Integrated Security=True" providerName="System.Data.SqlClient" /&gt;
  </code></pre>
  
  <p></p>