title: System.Data.SqlClient.SqlException: Invalid column name 'phone_types_phone_type_id'
body: <p>I'm trying to get information from some of my models that have a foreign key relationships to my main employee model. If I map out each model individually, I can access them like normal with no problems, but I have to visit multiple different web pages to do so.</p>
  
  <p>I'm trying to merge several of my models into essentially a single controller, and work with them this way. Unfortunately, when I try to access these models I get a strange error: </p>
  
  <blockquote>
    <p>System.Data.SqlClient.SqlException: Invalid column name 'phone_types_phone_type_id'.</p>
  </blockquote>
  
  <p>After searching through my code, apparently the only location <code>phone_types_phone_type_id</code> appears is in my migration code. I'm incredibly new at C# and Asp.Net in general so any help is appreciated.</p>
  
  <p>Here is the code for my model:</p>
  
  <pre><code>[Table("employee.employees")]
  public partial class employees1
  {
      public employees1()
      {
          employee_email_manager = new List&lt;email_manager&gt;();
          employee_employment_history = new HashSet&lt;employment_history&gt;();
          employee_job_manager = new HashSet&lt;job_manager&gt;();
          employee_phone_manager = new HashSet&lt;phone_manager&gt;();
          this.salaries = new HashSet&lt;salary&gt;();
      }
  
      [Key]
      public int employee_id { get; set; }
      [Display(Name="Employee ID")]
      public int? assigned_id { get; set; }
  
      [Display(Name="Web User ID")]
      public int? all_id { get; set; }
  
      [Required]
      [StringLength(50)]
      [Display(Name="First Name")]
      public string first_name { get; set; }
  
      [StringLength(50)]
      [Display(Name="Last Name")]
      public string last_name { get; set; }
  
      [Column(TypeName = "date")]
      [Display(Name="Birthday")]
      [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
      public DateTime birth_day { get; set; }
  
      [Required]
      [StringLength(1)]
      [Display(Name="Gender")]
      public string gender { get; set; }
  
      [Required]
      [StringLength(128)]
      [Display(Name="Social")]
      public string social { get; set; }
  
      [Required]
      [StringLength(128)]
      [Display(Name="Address")]
      public string address_line_1 { get; set; }
  
      [StringLength(50)]
      [Display(Name="Suite/Apt#")]
      public string address_line_2 { get; set; }
  
      [Required]
      [StringLength(40)]
      [Display(Name="City")]
      public string city { get; set; }
  
      [Required]
      [StringLength(20)]
      [Display(Name="State")]
      public string state { get; set; }
  
      [Required]
      [StringLength(11)]
      [Display(Name="Zip")]
      public string zip { get; set; }
  
      [Column(TypeName = "date")]
      [Display(Name="Hire Date")]
      [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
      public DateTime hire_date { get; set; }
  
      [Column(TypeName = "date")]
      [Display(Name="Separation Date")]
      [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
      public DateTime? termination_date { get; set; }
  
      [StringLength(70)]
      [Display(Name="Emergency Contact Name")]
      public string emergency_contact_name { get; set; }
  
      [StringLength(15)]
      [Display(Name = "Emergency Contact Number")]
      public string emergency_contact_phone { get; set; }
  
      [Display(Name = "Notes")]
      public string notes { get; set; }
  
      public virtual ICollection&lt;phone_manager&gt; employee_phone_manager { get; set; }
  
      [Table("employee.phone_manager")]
      public partial class phone_manager
      {
          [Key]
          public int phone_id { get; set; }
  
          public int employee_id { get; set; }
  
          [Required]
          [StringLength(15)]
          public string phone_number { get; set; }
  
          [StringLength(5)]
          public string phone_extension { get; set; }
  
          public int phone_type { get; set; }
  
          [Column(TypeName = "date")]
          public DateTime date_added { get; set; }
  
          public bool deleted { get; set; }
  
          public virtual employees1 employees1 { get; set; }
  
          public virtual phone_types phone_types { get; set; }
      }
  
      [Table("employee.phone_types")]
      public partial class phone_types
      {
          public phone_types()
          {
              phone_manager = new HashSet&lt;phone_manager&gt;();
          }
  
          [Key]
          public int phone_type_id { get; set; }
  
          [Required]
          [StringLength(50)]
          public string phone_type_name { get; set; }
  
          public virtual ICollection&lt;phone_manager&gt; phone_manager { get; set; }
      }
  }
  </code></pre>
  
  <p>And the pertinent code from my view:</p>
  
  <pre><code>        @foreach (var item in Model.employee_phone_manager)
          {
              @Html.DisplayFor(modelItem =&gt; item.phone_number); 
              @: - 
              @Html.DisplayFor(modelItem =&gt; item.phone_type);
              &lt;br /&gt;
          }
  </code></pre>
  
  <p><strong>EDIT</strong> I may have found out the issue, but I'll definitely take more input if there is another option. My solution was to take and add the following: <code>[ForeignKey("phone_type")]</code> directly above this line: <code>public virtual phone_types phone_types { get; set; }</code> in my <code>phone_manager</code> class.</p>