Dapper-Plus BulkInsert - 如何 return 受影响的行数?

Dapper-Plus BulkInsert - How to return number of rows affected?

Dapper-Plus中,有没有办法return数据库中受影响的行数?这是我的代码:

using (SqlConnection connection = new SqlConnection(Environment.GetEnvironmentVariable("sqldb_connection")))
{
    connection.BulkInsert(myList);
}

我看到您可以插入单行,但在 dapper plus bulk insert 上找不到功能。

由于 Dapper Plus 允许链接多个方法,该方法不会直接 ​​return 这个值。

但是,您可以使用以下代码来完成:

var resultInfo = new Z.BulkOperations.ResultInfo();

connection.UseBulkOptions(options => {
    options.UseRowsAffected = true;
    options.ResultInfo = resultInfo;
}).BulkInsert(orders);

// Show RowsAffected
Console.WriteLine("Rows Inserted: " + resultInfo.RowsAffectedInserted);
Console.WriteLine("Rows Affected: " + resultInfo.RowsAffected);

Fiddle: https://dotnetfiddle.net/mOMNng

请记住,使用该选项会使批量操作稍微变慢。

编辑:回答评论

will it make it as slow as using the regular dapper insert method or is this way still faster?

它仍然会比常规的快得多 Insert