title: how to inherit the values of a foreign key in MVC 5? Invalid column name 'student_student_name'
body: <p>I kept getting this error</p>
  
  <blockquote>
    <p>Invalid column name 'student_student_name'</p>
  </blockquote>
  
  <p>Here is my class for my database context</p>
  
  <pre><code>  public class CSdbConnectionString : DbContext
      {
          public CSdbConnectionString()
          : base("CSdbConnectionString")
          { }
  
          public DbSet&lt;appointment&gt; appointments { get; set; }
          public DbSet&lt;faculty&gt; faculties { get; set; }
          public DbSet&lt;sched&gt; scheds { get; set; }
          public DbSet&lt;student&gt; students { get; set; }
  
      }
  </code></pre>
  
  <p>My appointment class needs to inherit the values of the foreign key faculty and student</p>
  
  <pre><code> [Table("appointment")]
      public class appointment
      {
          [Key]
          [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
          public int appointment_id { get; set; }
          public string appointment_description { get; set; }
          public int student_id { get; set; }
          public int faculty_id { get; set; }
  
          public virtual student student { get; set; }
          public virtual faculty faculty { get; set; }
      }
  </code></pre>
  
  <p>Here is my faculty class</p>
  
  <pre><code>  [Table("faculty")]
      public class faculty
      {
          [Key]
          [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
          public int faculty_id { get; set; }
          public string faculty_name { get; set; }
  
          public string faculty_lname { get; set; }
  
          public string faculty_email { get; set; }
  
          public string faculty_password { get; set; }
  
          public string faculty_dept { get; set; }
      }
  </code></pre>
  
  <p>Here is my student class</p>
  
  <pre><code>[Table("student")]
      public class student
      {
          [Key]
          [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
          public string student_name { get; set; }
  
          public string student_lname { get; set; }
  
          public string student_email { get; set; }
          public string student_password { get; set; }
  
          public string student_number { get; set; }
  
          public string student_program { get; set; }
      }
  </code></pre>
  
  <p>The faculty class is working fine. I can inherit the values in my view</p>
  
  <pre><code> @item.faculty.faculty_name 
  </code></pre>
  
  <p>I also used <code>public virtual faculty faculty { get; set; }</code> in another class to inherit the faculty values and it worked fine. I did the same thing to inherit the values in student class and it kept saying invalid column name.</p>
  
  <p>I've already searched many solution here in stackoverflow and what happen is it just keeps getting new errors. </p>
  
  <p>I tried adding this to the parent class which will be the one inherited</p>
  
  <pre><code>public virtual ICollection&lt;appointment&gt; appointments { get; set; }
  </code></pre>
  
  <p>and added this code</p>
  
  <pre><code>protected override void OnModelCreating(DbModelBuilder modelBuilder)
          {
        modelBuilder.Entity&lt;appointment&gt;()
                   .HasRequired(c =&gt; c.student)
                    .WithMany(p =&gt; p.appointments)
                    .HasForeignKey(c =&gt; c.student_id);
              }
  </code></pre>
  
  <p>and still there are errors. </p>
  
  <p>All I did for the faculty to be inherited was add this to the child class <code>public virtual faculty faculty { get; set; }</code> and now I am trying to do the same with student and I always have errors. Can someone help me?</p>