我有两个表,user
和student
。user
是父表,student
是子表
所以从下面的代码
public void adduserStudenttype(StudentAddUserModel s)
{
using (DASEntities db = new DASEntities())
{
user u = new user();
u.usersEmail = s.Email;
u.usersPassword = s.Password;
u.usersFname = s.Fname;
u.usersUtype = s.UserType;
db.user.Add(u);
db.SaveChanges();
student stud = new student();
stud.studentID = \\ how to get the id in the user last insert??
}
}
我如何id
从user
表格中获取最后一个插入内容?id
是user
表中的主键。
您可以按以下方式获取它:
// I suppose that the corresponding's property name is ID.
// If it is not, you should change it correspondingly.
stud.studentID = u.ID;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句