我正在编写一种方法,必须保存对数据库中实体所做的更改。如何在我的Save方法中使用工作单元模式?
答案 0 :(得分:1)
参考经典的Martin Fowler的Unit of Work设计
所以基本上Save()就像这样
public void Save()
{
try
{
// save changes into database then commit
// ...
unitOfWork.Commit();
}
catch
{
unitOfWork.Rollback();
}
}
另请参阅stackexchange代码审查站点上的接口示例:Unit Of Work Interface