使用存储过程从Dapper.net查询返回值 [英] Return Values from Dapper.net query with stored procedure

查看:276
本文介绍了使用存储过程从Dapper.net查询返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Dapper.Net调用存储过程 并获取返回值。

I am trying to call a stored procedure using Dapper.Net and get return values.

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 值中包含正确的返回值,但是我无法按照描述的方式访问这些值

I have tried a couple of different things with the parameter direction and using the "@INCIDENT_ID". If you step through the results, you can see that the proper return values are coming down in the retResults value, but I am not able to access the values the way it is described in the documentation as below..

存储过程
Dapper支持完全存储的proc:

Stored Procedures Dapper supports fully stored procs:

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");   


推荐答案

您可以阅读以下值

var incidentId = retResults.ToList()[0].INCIDENT_ID; 

这篇关于使用存储过程从Dapper.net查询返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆