【发布时间】:2013-06-19 16:55:17
【问题描述】:
我正在尝试使用 SCOPE_IDENTITY 使用 DynamicParameter 的 ReturnValue 选项将长主键返回给 c#。
这是来自 Dapper 网站的示例代码:
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");
我宁愿执行以下操作,而不是返回 int,因为我的主键字段应该是 bigint
var p = new DynamicParameters();
p.Add("@a", 11);
p.Add("@b", dbType: DbType.Int32, direction: ParameterDirection.Output);
p.Add("@c", dbType: DbType.Int64, direction: ParameterDirection.ReturnValue);
cnn.Execute("spMagicProc", p, commandType: commandType.StoredProcedure);
int b = p.Get<int>("@b");
int c = p.Get<long>("@c");
在我的过程中,我使用的是“RETURN SCOPE_IDENTITY()”。
但是,这样做似乎会导致“指定的强制转换无效”。例外。
【问题讨论】:
-
你能澄清一下:这是 dapper.rainbow 吗?另外:您说该字段是“bigint”-大概现在涉及.net方面。在这里,你的意思是
BigInteger?还是您的意思是 Int64 又名long? SQL server 的 bigint 映射到 c# 中的long -
Dapper micro-orm(扩展)。当我提到 bigint 时,我指的是要保存到的表的主键字段。当我提到 long 时,这是我要写入的 .net 变量。
标签: c# stored-procedures dapper