Exemple #1
0
        /// <summary>
        /// 删除Demo
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public async Task <OperationResult <bool> > DeleteDemoAsync(long Id)
        {
            using (IDbTransaction tran = _demoRepository.BeginTransaction()) //开始事务
            {
                var result = new OperationResult <bool>();
                try
                {
                    string sql = "DELETE FROM Demo WHERE Id=@Id";
                    result.data = await _demoRepository.DeleteByIdAsync(Id, sql);

                    //result.data = await _demoRepository.DeleteAsync(Id);//dapper扩展方法
                    _demoRepository.CommitTransaction(tran);//提交事务
                    return(result);
                }
                catch (Exception ex)
                {
                    _demoRepository.RollbackTransaction(tran);//回滚事务
                    throw ex;
                }
            }
        }