Note that there are some explanatory texts on larger screens.

plurals
  1. POTable Value Parameter with Dapper stored procedures
    primarykey
    data
    text
    <p>I am attempting to call a stored procedure that accepts a table valued parameter.</p> <p>I am following guidelines on <a href="https://stackoverflow.com/q/6232978/20048">this</a> question, implementing a custom parameter type:</p> <pre><code>internal class IntDynamicParam { string name; IEnumerable&lt;int&gt; numbers; public IntDynamicParam(string name,IEnumerable&lt;int&gt; numbers) { this.name = name; this.numbers = numbers; } public void AddParameters(IDbCommand command) { var sqlCommand = (SqlCommand)command; sqlCommand.CommandType = CommandType.StoredProcedure; List&lt;Microsoft.SqlServer.Server.SqlDataRecord&gt; number_list = new List&lt;Microsoft.SqlServer.Server.SqlDataRecord&gt;(); // Create an SqlMetaData object that describes our table type. Microsoft.SqlServer.Server.SqlMetaData[] tvp_definition = { new Microsoft.SqlServer.Server.SqlMetaData("n", SqlDbType.Int) }; foreach (int n in numbers) { // Create a new record, using the metadata array above. Microsoft.SqlServer.Server.SqlDataRecord rec = new Microsoft.SqlServer.Server.SqlDataRecord(tvp_definition); rec.SetInt32(0, n); // Set the value. number_list.Add(rec); // Add it to the list. } // Add the table parameter. var p = sqlCommand.Parameters.Add("@" +name, SqlDbType.Structured); p.Direction = ParameterDirection.Input; p.TypeName = "int_list_type"; p.Value = number_list; } } </code></pre> <p>and am attempting to use this as follows:</p> <pre><code>var p = new DynamicParameters(); p.AddDynamicParams(new IntDynamicParam("@IDList", new int[] { 1000, 2000, 3000 })); p.Add("@StartRow", startRow); p.Add("@EndRow", endRow); p.Add("@OrderByField", orderByField.ToString()); p.Add("@OrderBy", orderBy.ToString()); p.Add("@TotalRows", 0, dbType: DbType.Int32, direction: ParameterDirection.Output); var v = cnn.Query&lt;venue&gt;(spName, p, commandType: CommandType.StoredProcedure).ToList&lt;IDBVenueLite&gt;(); </code></pre> <p>However the parameter '<em>@IDList</em>' is not passed. Clearly AddDynamicParams is not the way to go, can anyone help me out?</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.
 

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