[英]how to get the last insert ID in linq
我有两个表, 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??
}
}
如何从user
表中获取最后一个插入id
? 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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.