Note that there are some explanatory texts on larger screens.

plurals
  1. POOutput parameter is always null with multi.Read
    primarykey
    data
    text
    <p>We are using <a href="http://code.google.com/p/dapper-dot-net/" rel="nofollow">Dapper.Net</a> extensively and are very happy with it. However we have come across an issue when trying to retrieve output parameters from stored procedures using <strong>multi.Read</strong>:</p> <pre><code>var p = new DynamicParameters(); p.Add("@id", id); p.Add("TotalRows", dbType: DbType.Int32, direction: ParameterDirection.Output); using (var multi = cnn.QueryMultiple(string.Format("dbo.[{0}]", spName), p, commandType: CommandType.StoredProcedure)) { int TotalRows = p.Get&lt;int&gt;("@TotalRows"); //This is always null var results = multi.Read&lt;New_Supplier&gt;().ToList&lt;IDBSupplier&gt;(); var areas = multi.Read&lt;node&gt;().ToList&lt;IDBNode&gt;(); var categories = multi.Read&lt;node&gt;().ToList&lt;IDBNode&gt;(); int TotalRows = multi.Read&lt;int&gt;().FirstOrDefault(); // This works } </code></pre> <p>However, if we use the <strong>connection.Query</strong> syntax to get a single resultset the output parameter is populated:</p> <pre><code>var result = cnn.Query&lt;New_Supplier&gt;(string.Format("spname"), p, commandType: CommandType.StoredProcedure).ToList&lt;New_Supplier&gt;(); int TotalRows = p.Get&lt;int&gt;("@TotalRows"); </code></pre> <p>The error is that the sqlValue of AttachedParam on the output parameter in the Dapper DynamicParameters is always null. </p> <p>To work around this we have added the value of the output parameter to the result sets of the stored procedure and are reading it that way. </p> <p>Why is the parameter always null?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload