1 回答

TA貢獻(xiàn)1830條經(jīng)驗(yàn) 獲得超9個(gè)贊
創(chuàng)建一個(gè)模型以將 id 存儲(chǔ)在參數(shù)中。要獲取受影響的行,請(qǐng)獲取執(zhí)行調(diào)用的結(jié)果。
using (SqlConnection connection = new SqlConnection(_connectionString)) {
await connection.OpenAsync();
var affectedRows = await connection.ExecuteAsync(
ProcedureNames.DeleteRules,
new { id = ids.ToArray() }, //<-- Passing collection
commandType: CommandType.StoredProcedure);
}
另一種方法
using (SqlConnection connection = new SqlConnection(_connectionString)) {
await connection.OpenAsync();
var affectedRows = await connection.ExecuteAsync(
ProcedureNames.DeleteRules,
ids.Select(id => new { id = id }).ToArray(), //<-- Passing collection
commandType: CommandType.StoredProcedure);
}
會(huì)多次執(zhí)行該語(yǔ)句。對(duì)于數(shù)組列表中的每個(gè)對(duì)象一次。它仍然會(huì)為您提供執(zhí)行所有語(yǔ)句的受影響的總行數(shù)。
- 1 回答
- 0 關(guān)注
- 191 瀏覽
添加回答
舉報(bào)