How to use transactions with dapper.net?

后端 未结 5 743
夕颜
夕颜 2020-12-12 15:55

I would like to run multiple insert statements on multiple tables. I am using dapper.net. I don\'t see any way to handle transactions with dapper.net.

Please share y

5条回答
  •  無奈伤痛
    2020-12-12 16:27

    Here the code snippet:

    using System.Transactions;    
    ....    
    using (var transactionScope = new TransactionScope())
    {
        DoYourDapperWork();
        transactionScope.Complete();
    }
    

    Note that you need to add reference to System.Transactions assembly because it is not referenced by default.

提交回复
热议问题