我试图调用存储过程using Dapper.Net
并获取返回值。使用存储过程从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
值中正确的返回值降低,但我无法按照以下文档中描述的方式访问值。
存储过程 小巧玲珑的支持完全存储的特效:
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");
你是什么意思'我无法按照文档中描述的方式访问这些值' – MethodMan
你有没有尝试 'var IncidentID = con.Query(“usp_GetIncidentID”,commandType:CommandType.StoredProcedure).SingleOrDefault();'?如果你的存储过程通过“select”返回值,这是最简单的,并且可以工作。 –
2013-01-09 21:56:23
刚刚尝试过,我回来了 {DapperRow,INCIDENT_ID ='902306'},但我之前可以看到,但尝试访问该值时遇到问题。 – yellowfever