Linq插入不工作

本文关键字:工作 插入 Linq | 更新日期: 2023-09-27 18:09:18

我有这样的代码:

protected void Page_Load(object sender, EventArgs e)
{
    if (Page.IsPostBack)
    {
        using (mesteriEntities myEntities = new mesteriEntities())
        {
            var usern = Session["New"];
            var UserID = (from Users in myEntities.Users
                          where Users.UserName == usern
                          select Users.UserID).SingleOrDefault();
            var cati = Convert.ToInt32(DropDownList1.SelectedValue);
            Job newJob = new Job();
            newJob.categID = cati;
            newJob.userID = UserID;
            myEntities.AddToJobs(newJob);
        }
    }
}

当我选择一个组合时,它应该在Jobs表中添加combo的值和userID,两者都是INT值。变量"cati"answers"userid"有值

Linq插入不工作

myEntities.AddToJobs(newJob)调用后添加myEntities.SaveChanges()应该可以工作。以下是相关文档