c# - Dapper 多参数存储过程查询不会从数据库返回任何内容

标签 c# asp.net-web-api asp.net-core dapper

我一直在使用 Dapper 作为 .NET Core Web Api 的 ORM。

当使用 Dapper 使用一个参数从我的数据库查询存储过程时,它完全按照预期工作。当我添加多个参数时,它不会像应有的那样将任何内容返回到我的数据模型。

我怀疑这与我的语法或我构造查询的方式有关。我在下面使用的存储过程在 SSMS 查询窗口内执行时按预期工作。

这是我的方法,在我的 DAL 中包含 Dapper 查询:

public List<Players> C_GetAllActivePlayersInSport(int orgID, int sportID)
    {
        using (IDbConnection db = new SqlConnection(_connectionString))
        {
            var returnedData = db.Query<Players>("dbo.spPlayers_GetAllActivePlayers_by_Sport @orgID, @sportID", new { orgID = orgID, sportID = sportID }).ToList();

            return returnedData;
        }
    }

传入的值使其进入上面的方法和查询,但查询执行后,它返回一个计数为0的列表。

任何帮助将不胜感激!

最佳答案

尝试:

var returnedData = db.Query<Players>(
    "dbo.spPlayers_GetAllActivePlayers_by_Sport",
        new { orgID, sportID }, commandType: CommandType.StoredProcedure).ToList();

(注意:.AsList() 稍微更可取)

关于c# - Dapper 多参数存储过程查询不会从数据库返回任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51937392/

相关文章:

asp.net-web-api - 如何使ASP.NET WEB API帮助页面Xml文档注释具有新行

asp.net - 使用 Cookie 身份验证的 asp net core 项目 MVC Controller 和使用 Bearer 的 api 端点

asp.net-core - ASP.Net Core RC1 : System. ArgumentException:路径中存在非法字符

c# - 如何从我的模型类中分离反序列化属性?

c# - 在 C# 中确定字符串的编码

c# - 拦截asp.net core Authorize Action 授权成功后执行自定义 Action

javascript - 使用 id_token 作为重定向 URL 中的参数的重定向用户导致身份用户为 Null

c# - 以编程方式获取 nUnit 选择的类别

asp.net - 如何在WebAPI中获取POST数据?

angularjs - $http : how to get filename of headers from WebApi with CORS