_context.SaveChanges() 方法的问题

Issue with _context.SaveChanges() method

我遇到了一个奇怪的问题。

如果我从 addUpdateStudentDetails() 方法中删除 _context.SaveChanges(),则不会保存任何内容,而我希望得到保存,因为我的调用方法中确实有 _context.SaveChanges() 语句,即 update().

对吗?还是有其他原因造成的?

但是,如果我在我调用的方法中保留 _context.SaveChanges() 而不是添加/或修改的信息成功保存在数据库中。

public void update(StudentReport report)
{
    addUpdateStudentDetails(report);
    _context.Entry(original).CurrentValues.SetValues(report);
    _context.SaveChanges();
}

private void addUpdateStudentDetails(StudentReport report)
{
    using (var context = new DBContext())
    {
        if (student != null)
            context.Entry(orignal).State = EntityState.Modified;
        else 
            context.Student.Add(orignal);
        context.SaveChanges();
    }
}

addUpdateStudentDetails 已配置上下文。对 SaveChanges 的调用是在字段上执行的,而不是在同一上下文变量上执行的。