我有这段代码应该可以正常工作,但这会引发异常必须声明变量标量
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;
}
}
答案 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;
}
}