1 回答

TA貢獻1830條經驗 獲得超9個贊
創建一個模型以將 id 存儲在參數中。要獲取受影響的行,請獲取執行調用的結果。
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);
}
會多次執行該語句。對于數組列表中的每個對象一次。它仍然會為您提供執行所有語句的受影響的總行數。
- 1 回答
- 0 關注
- 177 瀏覽
添加回答
舉報