static void InsertData(int id) { var opTable1 = dborm.DB_TestDataBase1.DTOP_TABLE1; //获取对应数据库表的映射数据模型 //获取方法:dataModel = new DB_<数据库名>_DT_<表名>() //DB_TestDataBase1_DT_table1 对应 DB_<数据库名>_DT_<表名> 中的 //数据库名:TestDataBase1 //表名:table1 //获取对应表table1的数据model: modelTable1 var insertModel = new DB_TestDataBase1_DT_TABLE1(); insertModel.id = id; insertModel.age = 15; insertModel.name = "测试文字"; //插入数据 opTable1.InsertData(insertModel); }
/// <summary> /// 测试dborm的增删改查 /// </summary> static void Test() { //对表table1操作 //获取对应数据库表的数据到程序中 //获取方法:dborm.DB_<数据库名>.DTOP_<表名>.数据库操作函数() var opTable1 = dborm.DB_TestDataBase1.DTOP_TABLE1; var opTable2 = dborm.DB_TestDataBase1.DTOP_TABLE2; #region 插入数据 //1.插入操作 InsertData(1); //2.事务插入操作 opTable1.trans = dborm.DB_TestDataBase1.BeginTransaction(); try { InsertData(1); InsertData(1); InsertData(1); InsertData(3); opTable1.trans.Commit(); } catch (Exception ex) { opTable1.trans.Rollback(); } finally { dborm.DB_TestDataBase1.EndTransaction(); } //对表table2操作 var insertModel2 = new DB_TestDataBase1_DT_TABLE2(); insertModel2.id = "lucking"; insertModel2.price = 1223; insertModel2.num = 3; opTable2.InsertData(insertModel2); #endregion #region 查询数据 //查询方法1 var selectModel1 = new DB_TestDataBase1_DT_TABLE1(); DataTable dt1 = opTable1.QueryData("id ,age", null); for (int i = 0; i < dt1.Rows.Count; i++) { selectModel1.id = (int)dt1.Rows[i]["id"]; selectModel1.age = (int)dt1.Rows[i]["age"]; } //查询方法2 var selectModel2 = new DB_TestDataBase1_DT_TABLE1(); DataTable dt2 = opTable1.QueryData(); for (int i = 0; i < dt2.Rows.Count; i++) { selectModel2.id = (int)dt2.Rows[i]["id"]; selectModel2.age = (int)dt2.Rows[i]["age"]; selectModel2.name = (string)dt2.Rows[i]["name"]; } //查询方法3 Comb comb = new Comb(); SqlStr sql = new SqlStr(); SqlStr joinSql = new SqlStr(); sql.sql = "dbo.TABLE1.id = 3 "; joinSql.sql = "INNER JOIN dbo.TABLE2 R ON R.num = dbo.TABLE1.id"; DataTable dt3 = dborm.DB_TestDataBase1.DTOP_TABLE1.QueryData("dbo.TABLE1.*,R.id ids", sql, joinSql); for (int i = 0; i < dt3.Rows.Count; i++) { comb.id = (int)dt3.Rows[i]["id"]; comb.age = (int)dt3.Rows[i]["age"]; comb.name = (string)dt3.Rows[i]["name"]; comb.ids = (string)dt3.Rows[i]["ids"]; } #endregion }