public static T WithTransaction <T>(this IDataManagerFactory factory, Func <ITransactionDataManager, T> func, IsolationLevel level = IsolationLevel.ReadCommitted) { using (var manager = factory.GetTransactionManager(level)) { var result = func(manager); manager.Commit(); return(result); } }
public static T WithDataManager <T>(this IDataManagerFactory factory, Func <IDataManager, T> func, IsolationLevel?level = null) { using (var manager = level == null ? factory.GetManager() : factory.GetTransactionManager(level.Value)) { var result = func(manager); var transaction = manager as IUnitOfWork; if (transaction != null) { transaction.Commit(); } return(result); } }