我正在尝试从 Mysql 5.6.10 (AWS Aurora) 中的测试套件运行这个简单的 Dapper 示例。
var p = new DynamicParameters(new { a = 1, b = 2 });
p.Add("c", dbType: DbType.Int32, direction:ParameterDirection.Output);
cnn.Execute(@"set @c = @a + @b", p);
var results = p.Get<int>("@c");
我想使用两个输出参数来返回受插入语句影响的行数和最后插入的 ID。
最佳答案
我发现用dapper从mysql中获取参数似乎是不可能的,所以我修改了你的代码以达到结果。
var p = new DynamicParameters(new { a = 1, b = 2 });
//p.Add("c", dbType: DbType.Int32, direction: ParameterDirection.Output);
//conn.Execute(@"set @c = @a + @b", p);
using (var reader = conn.ExecuteReader(@"set @c = @a + @b; select @c;", p))
{
//var results = p.Get<int>("@c");
if (reader.Read())
{
var result = reader.GetInt32(0);
}
}
关于c# - Dapper 输出参数被 mysql 解释为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36819966/