小巧的人怎么了?

时间:2019-11-19 21:56:04

标签: dapper

我有这段代码应该可以正常工作,但这会引发异常必须声明变量标量

 public async Task<Job> GetJobByUd(Guid jobId)
    {
        var sql = "select * from dbo.Jobs where JobId = @jobId;";
        using (DbConnection db = new SqlConnection(_connectionString))
        {
            var job = await db.QuerySingleOrDefaultAsync<Job>(sql, new {jobId});
            return job;
        }

    }

1 个答案:

答案 0 :(得分:0)

尝试这样,应该可以。

public async Task<Job> GetJobByUd(Guid jobId)
    {
        var sql = "select * from dbo.Jobs where JobId = @jobId;";
        using (DbConnection db = new SqlConnection(_connectionString))
        {
            var job = await db.QueryAsync<Job>(sql, new {jobId = jobId}).FirstOrDefault();
            return job;
        }

    }