为什么要在 Query 方法中添加 CommandType?
Why would I add CommandType in Query method?
考虑以下代码:
public List<Author> Read()
{
using (IDbConnection db = new SqlConnection
(ConfigurationManager.ConnectionStrings["AdventureWorks"].ConnectionString))
{
string readSp = "GetAllAuthors";
return db.Query<Author>(readSp,commandType: CommandType.StoredProcedure).ToList();
}
}
为什么示例会在 return 中添加 commandType: CommandType.StoredProcedure
?
是否用于抗SQL注射?
我在这里得到示例:http://www.infoworld.com/article/3025784/application-development/how-to-work-with-dapper-in-c.html
告诉查询它是一个 StoredProcedure。
还可以尝试查看此 MSDN 文档 CommandType Enumaration and SQLCommand CommandType Property.
考虑以下代码:
public List<Author> Read()
{
using (IDbConnection db = new SqlConnection
(ConfigurationManager.ConnectionStrings["AdventureWorks"].ConnectionString))
{
string readSp = "GetAllAuthors";
return db.Query<Author>(readSp,commandType: CommandType.StoredProcedure).ToList();
}
}
为什么示例会在 return 中添加 commandType: CommandType.StoredProcedure
?
是否用于抗SQL注射?
我在这里得到示例:http://www.infoworld.com/article/3025784/application-development/how-to-work-with-dapper-in-c.html
告诉查询它是一个 StoredProcedure。 还可以尝试查看此 MSDN 文档 CommandType Enumaration and SQLCommand CommandType Property.