title: How to pass a null value into a stored procedure with Entity Framework?
body: <p>I have an MVC application using Entity Framework. I want to pass a parameter having a null value to a stored procedure. I want to pass MerchantID as <code>null</code> in some cases.</p>
  <pre><code>GetValues(int[] TicketID,int? MerchantID,bool IsOpen)
  {
  
  //TicketID has values 1123,1122 etc
  //MerchantID sometimes null
  //IsOpen true/false
  
    DataTable tbldepartmentid = new DataTable(&quot;Departmentid&quot;);
    tbldepartmentid.Columns.Add(&quot;VALUE&quot;, typeof(int));
    
    foreach (var id in TicketID)
        tbldepartmentid.Rows.Add(id);
  
   List&lt;GetTroubleTicketDetails_Result&gt; GetTroubleTicketDetails = _getTroubleTicketDetails_Result.ExecuteCustomStoredProc(&quot;Tickets.GetDetails&quot;, &quot; @GroupID,@MerchantID,@Open&quot;,
                   new SqlParameter(&quot;GroupID&quot;, SqlDbType.Structured) { Value = tbldepartmentid, TypeName = &quot;dbo.tblTVPForCSVINT&quot; }
                   , new SqlParameter(&quot;MerchantID&quot;, MerchantID)
                   , new SqlParameter(&quot;Open&quot;, IsOpen)).ToList();
                  return GetTroubleTicketDetails;
  }
  </code></pre>
  <p>My problem is that when I pass MerchantID=null, it gives me the below error:</p>
  <blockquote>
  <p>&quot;The parameterized query '(@GroupID [dbo].[tblTVPForCSVINT]
  READONLY,@MerchantID nvarchar(' expects the parameter '@MerchantID',
  which was not supplied.&quot;</p>
  </blockquote>
  <p>How can I pass a null value for MerchantID?</p>