//传入Sql语句事务测试 private bool InSqlTransactionTest(string mainId, string detailId) { //可以支持任意流行数据库类型,指定相关的数据库提供者即可(OracleProvider、SqlProvider、SqLiteProvider、MySqlProvider、DB2Provider、OleDbProvider) IDbProvider dbProvider = new SqlProvider(SystemInfo.BusinessDbConnectionString); bool result = true; try { dbProvider.BeginTransaction(); //主表 string sqlMain = string.Format("DELETE FROM CASE_PRODUCTIN_MAIN WHERE ID = {0}", mainId); dbProvider.ExecuteNonQuery(sqlMain); //子表 string sqlDetail = string.Format("DELETE FROM CASE_PRODUCTIN_DETAIL WHERE ID = {0}", detailId); dbProvider.ExecuteNonQuery(sqlMain); //事务提交 dbProvider.CommitTransaction(); } catch (Exception ex) { //事务回滚 dbProvider.RollbackTransaction(); result = false; } return(result); }
//增加实体语句事务测试 private bool InAddEntityTransactionTest() { //可以支持任意流行数据库类型,指定相关的数据库提供者即可(OracleProvider、SqlProvider、SqLiteProvider、MySqlProvider、DB2Provider、OleDbProvider) IDbProvider dbProvider = new SqlProvider(SystemInfo.RDIFrameworkDbConectionString); bool result = true; try { dbProvider.BeginTransaction(); //主表 CASE_PRODUCTIN_MAINManager manager = new CASE_PRODUCTIN_MAINManager(dbProvider, Utils.UserInfo); CASE_PRODUCTIN_MAINEntity mainEntity = new CASE_PRODUCTIN_MAINEntity { ID = BusinessLogic.NewGuid(), INDATE = BusinessLogic.ConvertToNullableDateTime(DateTime.Now), SUPPLIERNAME = "Test" }; string key = manager.AddEntity(mainEntity); //子表 CASE_PRODUCTIN_DETAILManager detailManager = new CASE_PRODUCTIN_DETAILManager(dbProvider, Utils.UserInfo); CASE_PRODUCTIN_DETAILEntity detailEntity = new CASE_PRODUCTIN_DETAILEntity { ID = BusinessLogic.NewGuid(), CASE_PRODUCTIN_MAIN_ID = key }; string key1 = detailManager.AddEntity(detailEntity); //事务提交 dbProvider.CommitTransaction(); } catch (Exception ex) { //事务回滚 dbProvider.RollbackTransaction(); result = false; } return(result); }