C# MySQL,Dapper Trans,list

大憨熊 提交于 2019-11-26 16:59:25

static async Task MySQLTransDemo()
{

try
{
using(dbConnection)
{
dbConnection.Open();

//The object matched type such as class must have the column fields in table
List<object> objList = new List<object>();
//assign values to objList;
//to-do
//objList=GetObjList();
using(IDbTransaction trans=dbConnection.BeginTransaction())
{
//match columns and values respectively.
string transSQL = "insert into table_Name(column1,column2) values(@column1,@column2)";
//In this example,this objList collection's item object must have column1 and column2 properties.
var transNum = await dbConnection.ExecuteAsync(transSQL, objList, trans);
trans.Commit();
if(transNum<0)
{
trans.Rollback();
}
}
}
}

catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!