title: Foreignkey Name error in Entity Framework Code First
body: <p>When I'm using the following code, the tables are generated successfully with the Primary key and Foreign Key relations.</p>
  
  <pre><code> [Table("tblDepartments")]
      public class DepartmentModel
      {
          [Key]
          public int DepartmentID { get; set; }
          public string Name { get; set; }
          public string Location { get; set; }
          public ICollection&lt;EmployeeModel&gt; Employees { get; set; }
      }
  
  
  
      [Table("tblEmployees")]
      public class EmployeeModel
      {
          [Key]
          public int EmployeeID { get; set; }
          public string Name { get; set; }
          public string Gender { get; set; }
          public string City { get; set; }      
          public virtual DepartmentModel DID { get; set; }
  
      }
  </code></pre>
  
  <p>But when I use the following Code, I'm Getting error:</p>
  
  <pre><code>[Table("tblDepartments")]
      public class DepartmentModel
      {
          [Key]
          public int DepartmentID { get; set; }
          public string Name { get; set; }
          public string Location { get; set; }
          public ICollection&lt;EmployeeModel&gt; Employees { get; set; }
      }
  
  
  
      [Table("tblEmployees")]
      public class EmployeeModel
      {
          [Key]
          public int EmployeeID { get; set; }
          public string Name { get; set; }
          public string Gender { get; set; }
          public string City { get; set; }     
  
          [ForeignKey("DeptID")]
          public virtual DepartmentModel DID { get; set; }
  
      }
  </code></pre>
  
  <p><strong>ERROR:</strong></p>
  
  <blockquote>
    <p>The ForeignKeyAttribute on property 'DID' on type
    'MvcApplication1.Models.EmployeeModel' is not valid. The foreign key
    name 'DeptID' was not found on the dependent type
    'MvcApplication1.Models.EmployeeModel'. The Name value should be a
    comma separated list of foreign key property names.</p>
  </blockquote>
  
  <p>Please Help. Thanks in advance.</p>