我有用户和人员表。一个用户有很多人。当我向现有用户添加新人员时,我是否必须检索用户对象并向其添加新人员,或者将用户 ID 指定给人员对象是否足够?
public void InsertUpdatePerson(int? personId, string firstName, string lastName,
string middleName, DateTime dob, string mobile, string email, int userid)
{
using (DBEntities context = new DBEntities())
{
Person pers;
if (personId.HasValue)
{
pers = context.People.Where(p => p.PersonID == personId).FirstOrDefault();
pers.FirstName = firstName;
pers.LastName = lastName;
pers.MiddleName = middleName;
pers.DOB = dob;
pers.Mobile = mobile;
pers.Email = email;
pers.UserID = userid;
}
}
}