我有上面两个表,在部门表中PersonID
是表的外键PersonalInfo
。我有一个 Web 表单,其中包含 FirstName、SecondName、MobileNo 和 Department 文本框。所以我在PersonID
插入Department
.
你能告诉我如何通过使用 linq to entityframework 来存储部门的PersonalInfo
ID吗?PersonID
这是我的代码:
PersonalInfo myRecipient = new PersonalInfo();
myRecipient.FirstName = id_firstName.ToString();
myRecipient.SecondName = id_lastName.Text.ToString();
myRecipient.MobileNo = id_mobileNo.Text.ToString();
Department myDepartment = new Department();
myDepartment.Department1 = id_departmentName.Text.ToString();
MyEntity myDB = new MyEntity();
myDB.AddToPersonalInfoes(myRecipient);
myDB.AddToDepartments(myDepartment);
myDB.SaveChanges();