Entity Framework - Insert from two enties in EF
Asked By anbu n on 30-Jan-14 04:30 AM
in
a controller , where inserting Employee datas (Employee Entity class),
here a drop down is binded from Department Entity Class.
Here how to
save Employee datas with department values which is from different
entity class in EF , because its showing validation error
[Table("tblEmployee")]
public class Employee
{
[Key]
public int EmpNo { get; set; }
public string Ename { get; set; }
public string Designation { get; set; }
public decimal Salary { get; set; }
public int Mgrno { get; set; }
[DataType(DataType.Date)]
public DateTime DateofBirth { get; set; }
[DataType(DataType.Date)]
public DateTime DateofJoining { get; set; }
[ForeignKey("Department")]
public int DepNo { get; set; }
public virtual Department Department { get; set; }
//public Department Department { get; set; }
}
----------------
[Table("tblDepartment")]
public class Department
{
public string Dname { get; set; }
public string Location { get; set; }
[Key]
public int DepNo { get; set; }
}