Foreign Key In Code First
Answers (1)
Add AnswerThe best way to apply Foreign Key in Code First is,
public class Employee { public int EmployeeId{ get; set; } public string EmployeeName { get; set; } [ForeignKey("Department")] public int DeptId{ get; set; } public Department Department { get; set; } } public class Department { public int DepartmentID{ get; set; } public string DepartmentName{ get; set; } public ICollection<Employee> Employee { get; set; } }
I hope this will help you.