繁体   English   中英

如何获取linq中的最后一个插入ID

[英]how to get the last insert ID in linq

我有两个表, userstudent 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 iduser表中的主键。

您可以按以下方式获取它:

// 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM