using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServerW3Schools()))
{
var sql = "Select * FROM CUSTOMERS WHERE CustomerID in @abc";
var affectedRows = connection.Execute(sql, new { abc = 53 });
connection.BulkDelete(connection.Query<Customer>(sql).ToList());
}
以上代码无法正常工作。可以使用任何方法代替直接在查询“ connection.BulkDelete(connection.Query(” Select * FROM(CUSTOMERS WHERE CustomerID in(53)“).ToList()); ”)中传递值。将弹性值传递给BulkDelete?谢谢
答案 0 :(得分:0)
您没有使用受影响的行:
using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServerW3Schools()))
{
var sql = "Select * FROM CUSTOMERS WHERE CustomerID in @abc";
var affectedRows = connection.Execute<Customer>(sql, new { abc = 53 });
connection.BulkDelete(affectedRows.ToList());
}
答案 1 :(得分:0)
我不知道BulkDelete
的工作方式;没用过。但是,我认为您的查询中存在语法错误。 IN
子句的输入应放在圆括号内,如下所示:
var sql = "Select * FROM CUSTOMERS WHERE CustomerID in (@abc)";
观察上面的圆括号。
connection.BulkDelete(connection.Query("Select * FROM CUSTOMERS WHERE CustomerID in (53)").ToList());
您可以看到,这里的参数包含在圆括号中。