I've been using Dapper to call stored procedures passing it an object. For example:
If I have an object:
public int ID { get; set; }
public int Year { get; set; }
I can create this object and pass it to my Execute
call as the parameters. Dapper automatically maps all of those properties into parameters and executes the stored procedure. Awesome.
What about output parameters? If my object looked like the following how can I get Dapper to populate that property with the output parameter value?
public int ID { get; set; }
public int Year { get; set; }
public int OutputParameter { get; set; }
Do output parameters have to be added as DynamicParameters
?
Something like this:
DynamicParameters _params = new DynamicParameters();
_params.Add("@newId", DbType.Int32, direction: ParameterDirection.Output);
var result = connection.Execute("[dbo].YourProc", _params, null, null, CommandType.StoredProcedure);
var retVal = _params.Get<int>("newId");