我想提交一個事務到我的Sql Server 2008數據庫 - 首先是2個插入的後面是幾個更新,但是,只要它試圖執行第一個更新,我就會得到以下錯誤:Dapper.net交易問題
ExecuteNonQuery requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized.
下面的代碼,爲了簡潔而稍加編輯:
using (_cn)
{
_cn.Open();
IDbTransaction transaction = _cn.BeginTransaction();
topicId = (int)_cn.Query<decimal>(qAddTopic, new { pForumId = topic.ForumId }, transaction).Single();
postId = (int)_cn.Query<decimal>(qAddPost, new { pTopicId = topicId }, transaction).Single();
_cn.Execute(qUpdateForums, new { pLastPostId = postId });
_cn.Execute((qUpdateSiteTotals));
transaction.Commit();
}
第2個插入做工精細,但只要它會嘗試進行更新的一個,沒有喜悅。
'Connection.Query(「sqlQuery」,param:new { id = ID},transaction:Transaction)' –
vaheeds