我正在尝试调用存储过程使用 Dapper.Net
并获取返回值。
p.Add("@INCIDENT_ID", dbType: DbType.Int32, direction: ParameterDirection.ReturnValue);
var retResults = con.Execute("usp_GetIncidentID", p, commandType:CommandType.StoredProcedure);
int IncidentID = p.Get<int>("INCIDENT_ID");
我在参数方向和使用 "@INCIDENT_ID"
方面尝试了几种不同的方法。如果逐步查看结果,您会看到 retResults
值中出现了正确的返回值,但我无法按照下面文档中描述的方式访问这些值。 .
存储过程 Dapper 支持完全存储的过程:
var user = cnn.Query<User>("spGetUser", new {Id = 1},
commandType: CommandType.StoredProcedure).First();}}}
If you want something more fancy, you can do:
var p = new DynamicParameters();
p.Add("@a", 11);
p.Add("@b", dbType: DbType.Int32, direction: ParameterDirection.Output);
p.Add("@c", dbType: DbType.Int32, direction: ParameterDirection.ReturnValue);
cnn.Execute("spMagicProc", p, commandType: commandType.StoredProcedure);
int b = p.Get<int>("@b");
int c = p.Get<int>("@c");
最佳答案
我怀疑(未经测试)这纯粹是您命名参数的方式不匹配;尝试(注意删除的 @
):
p.Add("INCIDENT_ID", dbType: DbType.Int32, direction: ParameterDirection.ReturnValue);
var retResults = con.Execute("usp_GetIncidentID", p, commandType:CommandType.StoredProcedure);
int IncidentID = p.Get<int>("INCIDENT_ID");
关于c# - 使用存储过程从 Dapper.net 查询返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14247081/