コード例 #1
0
        public async Task <TResponse> Handle(TRequest message)
        {
            try
            {
                _db.BeginTransaction();

                var response = await _inner.Handle(message);

                await _db.CommitTransactionAsync();

                return(response);
            }
            catch (Exception)
            {
                _db.RollbackTransaction();
                throw;
            }
        }
コード例 #2
0
        public TResponse Handle(TRequest message)
        {
            try
            {
                _db.BeginTransaction();

                var response = _inner.Handle(message);

                _db.CommitTransactionAsync().Wait();

                return(response);
            }
            catch (Exception)
            {
                _db.RollbackTransaction();
                throw;
            }
        }
コード例 #3
0
        public void DoClean(Action <DbContext> action)
        {
            var connString = LocalDbFactory.Instance.CreateConnectionStringBuilder();

            connString.InitialCatalog = "ContosoUniversity";
            var dbContext = new SchoolContext(connString.ToString());

            try
            {
                dbContext.BeginTransaction();
                action(dbContext);
                dbContext.CloseTransaction();
            }
            catch (Exception e)
            {
                dbContext.CloseTransaction(e);
                throw;
            }
        }