I have two Model classes: Attendance and Employee. I have defined the Employee class as:
public class Employee
{
public int Id { get; set; }
public string Username { get; set; }
public string Password { get; set; }
}
Then I have defined the Attendance class as:
public class Attendance
{
public int Id { get; set; }
public Employee Employee { get; set; } //This is the foreign key
public DateTime LoginDate { get; set; }
public DateTime LogoutDate { get; set; }
}
When I am trying to insert data into Employee table it works fine, but when I try to insert data inside Attendance table it shows an exception. I am checking the Employee properly and inserting only one row of Employee inside the Attendance table.
Here is an image of the exception: