title: how to pass key-value pair into a user-defined table type?
body: <p><strong>How do I pass a Dictionary or any other tuple type into a stored procedure?</strong></p>
  
  <p>The stored procedure is defined as:</p>
  
  <pre><code>CREATE PROCEDURE [dbo].[Components]
  (
    @OrderTypeID INT = NULL,
    @OrderTypeKey VARCHAR(40) = NULL,
    @SegmentID INT = NULL,
    @SegmentKey VARCHAR(40) = NULL,
    @FilterPairs KeyValuePair READONLY
  )
  AS 
  BEGIN
  ..
  </code></pre>
  
  <p>Where <code>KeyValuePair</code> is defined as:</p>
  
  <p><a href="https://i.stack.imgur.com/IwvI3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IwvI3.png" alt="enter image description here"></a></p>
  
  <p>This is how I am calling the sproc:</p>
  
  <pre><code>context.Database.SqlQuery&lt;EntityType&gt;(
      @"declare param1 int = --some logic
        declare param2 varchar = --some logic
        EXEC Components @param1=@param1,@param2=@param2"
  );
  </code></pre>
  
  <p><strong>How do I pass a Dictionary or any other tuple type into a stored procedure for a user-defined table-type parameter?</strong></p>
  
  <p>Please note that I do not want to use <a href="https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparameter(v=vs.110).aspx" rel="nofollow noreferrer"><code>SqlParameter</code></a> for this implementation if possible.</p>