我目前正在使用的系统使用所有数据访问的存储过程。我目前正在研究Dapper(迄今为止它看起来很棒),但我想知道是否可以使用使用Template创建的DynamicParameters对象,但将其中一个参数设置为输出参数。例如:我可以在Template中使用DynamicParameters并在dapper中使用返回参数吗?
SP:
CREATE PROCEDURE InsertPerson
@ID int Output,
@Name varchar(100),
@DOB DateTime2
AS
--INSERT STATEMENT
SET @ID = SCOPE_IDENTITY()
POCO:
internal class Person
{
public int ID { get; set; }
public string Name { get; set; }
public DateTime DOB { get; set; }
}
代码:
var procParams = new DynamicParameters(person);
connection.Execute("InsertPerson", procParams, commandType: CommandType.StoredProcedure);
// This is where i'm having the issue, can it be done?
person.ID = procParams.Get<int>("ID");
目前我收到一个错误,因为键没有被发现。有没有办法获得ID输出参数,而无需手动设置所有存储的procs参数?
+1为解释和项目更新这导致 –
看起来不错,离开我的笔记本电脑在办公室周末,但我会检查星期一。谢谢! – Fermin
@Fermin做到了吗? –