为什么我要在查询方法中添加CommandType

本文关键字:添加 CommandType 方法 查询 我要 为什么 | 更新日期: 2023-09-27 18:12:23

考虑以下代码:

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();
           }
    }

为什么示例会在返回中添加commandType: CommandType.StoredProcedure ?

是用于反sql注入吗?

我在这里得到的例子:http://www.infoworld.com/article/3025784/application-development/how-to-work-with-dapper-in-c.html

为什么我要在查询方法中添加CommandType

告诉查询它是一个StoredProcedure。还可以尝试查看此MSDN文档CommandType枚举和SQLCommand CommandType属性。