title: How to call a stored procedure that has several types in C# on .NET Core
body: <p>I wrote a stored procedure that takes two types I created as parameters, called <code>Type1</code> and <code>Type2</code> :</p>
  <pre><code>CREATE TYPE Type1 AS TABLE
  (
      Id [int] NULL,
      Value [float] NULL
  )
  
  CREATE TYPE Type2 AS TABLE
  (
      Id [int] NULL,
      Name [varchar](20) NULL,
      Value [float] NULL
  )
  
  CREATE PROCEDURE [SP-Name]
      (@Id INT = 1,
       @UserName VARCHAR(500) = 'test',
       @Item1 Type1 READONLY,
       @Item2 Type2 READONLY)
  AS
  BEGIN
      SELECT * 
      FROM @Item1
  END;
  </code></pre>
  <p>When I call this stored procedure in SQL Server itself, it runs without error, but I write the same code in C#, I get an error. What is the problem?</p>
  <p>This is how I call this stored procedure in C#:</p>
  <pre><code>ENTITIES.SqlQuery&lt;Result&gt;($&quot;EXEC [SP-Name] @Item1&quot;,
        new[] {
                 new SqlParameter
                 {
                     SqlDbType = SqlDbType.Structured,
                     TypeName = &quot;Type1&quot;,
                     Value = listItems.ToDataTable(),//Get list Item from database and Convert to DATA-TABLE
                     ParameterName = &quot;Item1&quot;
                 }}).ToList();
  
  public class Result 
  {
      public int Id { get; set; }
      public string Value { get; set; }
  }
  
  public static DataTable ToDataTable&lt;T&gt;(this List&lt;T&gt; items)
  {
          DataTable dataTable = new DataTable(typeof(T).Name);
  
          // Get all the properties
          PropertyInfo[] Props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
  
          foreach (PropertyInfo prop in Props)
          {
              // Defining type of data column gives proper data table 
              var type = (prop.PropertyType.IsGenericType &amp;&amp; prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable&lt;&gt;) ? Nullable.GetUnderlyingType(prop.PropertyType) : prop.PropertyType);
  
              // Setting column names as Property names
              dataTable.Columns.Add(prop.Name, type);
          }
  
          foreach (T item in items)
          {
              var values = new object[Props.Length];
  
              for (int i = 0; i &lt; Props.Length; i++)
              {
                  // inserting property values to datatable rows
                  values[i] = Props[i].GetValue(item, null);
              }
  
              dataTable.Rows.Add(values);
          }
  
          // put a breakpoint here and check datatable
          return dataTable;
      }
  </code></pre>
  <p>This is the error I get:</p>
  <blockquote>
  <p>Operand type clash: Item1 is incompatible with int</p>
  </blockquote>