【发布时间】:2013-03-26 06:13:10
【问题描述】:
我有一个利用三层优势的 asp.net 应用程序: DAL -> 实现 EntityFramework 的 IUnitOfWork 接口 BLL -> 一组业务逻辑类,其中 evenry 类从基本业务逻辑类继承 UI -> 网络表单
Base business logic class appears like following
public class BasebusinessLogicClass<TEntity>
ctor(IUnitOfWork uow){this.Unit = uow)
public void Insert(T entity) { // add entity on unit context and call SaveChanges}
public void Edit(T entity) { // edit entity on unit context and call SaveChanges}
public void Delete ..// as the above snippet..
正如您在我的代码 sn-p 中看到的,每个业务逻辑类都执行“原子”业务操作。每次调用 Insert、Delete、Edit 方法都会调用 SaveChanges()。 现在,我需要实现一种事务,其范围必须限制在类上,例如:
public class BusinessTransactionBase
private collection of BusinessLogicBase;
public void Begin() {..initialize the TransactionScope class of .NET}
public void Commit() {Call Complete methid of transactionScope}
public void Rollback() {Dispose transasctionScope object}
public BusinessObjectBase<T> LoadBusinessObject<T>(){ return business logic base of T entity}
好吧,我正在寻找的是只允许在事务中加入 businessLogicBase 的私有集合。因此,如果从另一个角度执行类似“PersonLogicBase.Insert(T item).. AND 我的事务将回滚”,则 PersonLogicBase.Insert(T item) 不会受到撤消操作的影响。
据我所知,实现这一目标的唯一方法是在分离的线程上实例化每个 BusinessTransaction 对象,但我会使用更好/更简单的解决方案。
有什么想法吗?
【问题讨论】:
标签: c# entity-framework entity transactionscope