小编yel*_*ver的帖子

使用存储过程从Dapper.net查询返回值

我试图调用存储过程using 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"); 
Run Code Online (Sandbox Code Playgroud)

我已经尝试了几个与参数方向不同的东西并使用了"@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");   
Run Code Online (Sandbox Code Playgroud)

c# sql-server dapper

12
推荐指数
2
解决办法
3万
查看次数

标签 统计

c# ×1

dapper ×1

sql-server ×1