How with Dapper to automatically map output parameters?

dapper sql

Question

I've been calling stored procedures using Dapper and handing it an object. For instance:

If I have a possession:

public int ID { get; set; }    
public int Year { get; set; }

This product may be made by me and given to myExecute as the call's arguments. All of those characteristics are automatically converted into parameters by Dapper, who also runs the stored method. Awesome.

How about the output variables? How can I get Dapper to set that property with the output parameter value if my object has the following appearance?

public int ID { get; set; }    
public int Year { get; set; }
public int OutputParameter { get; set; }

Are output parameters necessary to provide asDynamicParameters ?

1
6
12/14/2015 3:37:42 PM

Popular Answer

Possibly 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");
1
12/14/2015 5:22:16 PM


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow