Rdiframework.net framework compatible with various database type transactions use example reference
The rdiframwork.net framework has a good control over the transaction of the database, it provides good support for the execution of multiple tables or multiple statements in the same transaction, and supports any major type of database, the following code can be used as a reference for the user. Users can use any extension.
1. Incoming entities perform execution transaction testing
Private BOOLInentitytransactiontest (stringMainid,stringdetailid) { //can support any popular database type and specify the relevant database provider (Oracleprovider, SQLProvider, Sqliteprovider, Mysqlprovider, Db2provider, Oledbprovider)Idbprovider Dbprovider =NewOracleprovider (systeminfo.businessdbconnectionstring); BOOLresult =true; Try{dbprovider.begintransaction (); //Main TableCase_productin_mainmanager Manager =NewCase_productin_mainmanager (Dbprovider, utils.userinfo); Case_productin_mainentity mainentity=Manager. GetEntity (Dbprovider.sqlsafe (Mainid)); Manager. Delete (mainentity); //child tableCase_productin_detailmanager Detailmanager =NewCase_productin_detailmanager (Dbprovider, utils.userinfo); Case_productin_detailentity detailentity=detailmanager.getentity (Dbprovider.sqlsafe (detailid)); Detailmanager.delete (detailentity); //Transaction Commitdbprovider.committransaction (); } Catch(Exception ex) {//Transaction Rollbackdbprovider.rollbacktransaction (); Result=false; } returnresult;}
2. Incoming SQL statement transaction Test
Private BOOLInsqltransactiontest (stringMainid,stringdetailid) { //can support any popular database type and specify the relevant database provider (Oracleprovider, SQLProvider, Sqliteprovider, Mysqlprovider, Db2provider, Oledbprovider)Idbprovider Dbprovider=NewSQLProvider (systeminfo.businessdbconnectionstring); BOOLresult =true; Try{dbprovider.begintransaction (); //Main Table stringSqlmain =string. Format ("DELETE from Case_productin_main WHERE ID = {0}", Mainid); Dbprovider.executenonquery (Sqlmain); //child table stringSqldetail =string. Format ("DELETE from case_productin_detail WHERE ID = {0}", Detailid); Dbprovider.executenonquery (Sqlmain); //Transaction Commitdbprovider.committransaction (); } Catch(Exception ex) {//Transaction Rollbackdbprovider.rollbacktransaction (); Result=false; } returnresult; }
Erichu Source: http://www.cnblogs.com/huyongEmail: [Email protected]qq exchange: 406590790 Platform Blog: "CSDN" http://blog.csdn.net/ Chinahuyong "Cnblogs" Http://www.cnblogs.com/huyong about senior engineer, information System Project Manager, DBA. Focus on Microsoft Platform Project architecture, management and enterprise solutions, multi-year project development and management experience, has organized and developed several large projects, proficient in dotnet,db (SQL Server, Oracle, etc.) technology. Familiar with Java, DELHPI and Linux operating system, have solid network knowledge. has some attainments in object-oriented, service-oriented and database fields. Currently engaged in DB management and development, WinForm, WCF, WebService, Web page Data capture and ASP, such as project management, development, architecture and other work. If you have any questions or suggestions, please enlighten me! This article is copyright to the author and Cnblogs blog, welcome to reprint, but without the author's consent must retain this paragraph statement, and in the article page obvious location to the original connection, if there is a problem, you can contact me by email or QQ, thank you very much.
Rdiframework.net framework compatible with various database type transactions use example reference