我正在与另一位开发人员讨论是否要repo.SaveChanges()在我们的 Entity Framework 5 存储库中公开一个方法。
我们正在考虑有一个自动保存这样的更改的仓库(快速而肮脏的例子):
public class Repo {
    private OurEfContext _context = new OurEfContext();
    public void PersistCustomer(Customer cust)
    {
        // update customer code here
        _context.SaveChanges(); //  <-- is this okay?
    }
}
我们正在考虑的另一个选项是公开一个单独的 Repo.PersistChanges() 方法,如下所示:
public class Repo {
    private OurEfContext _context = new OurEfContext();
    public void PersistCustomer(Customer cust)
    {
        // update customer code here
        // no call to _context.SaveChanges();
    }
    public void PersistChanges()
    {
        _context.SaveChanges();
    }
}
我见过的大多数例子都使用第二种模式。一种模式比另一种更“正确”吗?