I am trying to define a one-to-many relationship between my two table in Entity Framework in .net 3.5.
City Table
CityId
CityName
Employee Table
EmployeeId
EmployeeName
RegistrationDate
FK_CityID
I am trying to insert Data in Employee all data inserted Perfectly but FK_CityID is instred NULL.
Insert Button click Code DateTime dt = new DateTime(2008, 12, 12);
EmployeeService es = new EmployeeService();
CityService cs = new CityService();
Payroll.Entities.Employee e1 = new Payroll.Entities.Employee();
Payroll.Entities.City city1 = cs.SelectCity(Convert.ToInt32(cmbCity.SelectedItem.Value));
e1.FK_CityID = city1;
e1 = Payroll.Entities.Employee.CreateEmployee(0, "Archana",dt);
es.AddEmpoyee(e1);
In e1.City I am Passing whole object that is city1(object of city) and it is passing Perfectly but In database it will save NULL
MyService Class is
public string AddEmpoyee(Payroll.Entities.Employee e1)
{
//DAO
Payroll_DAO payrollDAO = new Payroll_DAO();
payrollDAO.AddToEmployee(e1);
payrollDAO.SaveChanges();
return "SUCCESS";
}
I am not getting where I am wrong...