1

我的 dapper 工作正常,但它是不安全的,因为我没有使用参数,我怎样才能最好地将我的 dapper 变量转换为参数,例如这是我工作的未参数化代码..

var getinfo = sqlConnection.Query<test>("Select name,location from tests where location="+ myplace).FirstOrDefault();

myplace是用户放置信息的文本框,现在当我尝试参数化该代码时

var getinfo = sqlConnection.Query<test>("Select name,location from tests where location='@location'", new {location = myplace}).FirstOrDefault();

我绝对没有返回,但没有错误消息。我在这里可以缺少什么或参数化变量的最佳方法是什么。

4

1 回答 1

2

您不需要在参数周围放置单引号。希望这可以帮助。

var getinfo = sqlConnection.Query<test>("Select name,location from tests where location=@location", new {location = myplace}).FirstOrDefault();
于 2013-03-07T20:36:42.450 回答