The system I am currently working on uses Stored Procedures for all data access. I'm looking into Dapper at the moment (so far it looks great) but I was wondering if I can use a DynamicParameters object created using a Template but make one of the parameters an output param. For example:
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; }
}
Code:
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");
Current I receive an error because the key was not found. Is there a way to get the ID output parameter without manually setting up all of the stored procs parameters?