我正在尝试使用 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()”。
然而,这样做似乎会导致“指定的演员无效”。例外。