title: How do I use 'Where In' in Dapper
body: <p>I've been trying unsuccessfully now for a while to use an <code>IEnumerable&lt;string&gt;</code> with a <code>WHERE IN</code> clause in Dapper.</p>
  
  <p>In the documentation, it does say that <code>IEnumerable&lt;int&gt;</code> is supported for use in a <code>WHERE IN</code> but I can't even get that to work.</p>
  
  <p><a href="http://code.google.com/p/dapper-dot-net/" rel="noreferrer"><code>Dapper allow you to pass in IEnumerable&lt;int&gt; and will automatically parameterize your query.</code></a></p>
  
  <p>The error message I keep receiving is an Sql syntax error. <code>Incorrect syntax near ','.</code></p>
  
  <p>I've put together some test code that I hope will demonstrate what I am trying to achieve.</p>
  
  <hr>
  
  <pre><code>string connString = "Server=*.*.*.*;Database=*;User Id=*;Password=*;";
  
  string sqlStringIn = @"SELECT StringText FROM 
                  (SELECT 1 ID, 'A' StringID, 'This is a test' StringText
                  UNION SELECT 2 ID, 'B' StringID, 'Another test' StringText
                  UNION SELECT 3 ID, 'C' StringID, 'And another' StringText
                  UNION SELECT 4 ID, 'D' StringID, 'and again' StringText
                  UNION SELECT 5 ID, 'E' StringID, 'yet again' StringText) data
                  WHERE StringId IN (@str)";
  
  string sqlIntegerIn = @"SELECT StringText FROM 
                  (SELECT 1 ID, 'A' StringID, 'This is a test' StringText
                  UNION SELECT 2 ID, 'B' StringID, 'Another test' StringText
                  UNION SELECT 3 ID, 'C' StringID, 'And another' StringText
                  UNION SELECT 4 ID, 'D' StringID, 'and again' StringText
                  UNION SELECT 5 ID, 'E' StringID, 'yet again' StringText) data
                  WHERE ID IN (@integer)";
  
  
  using (SqlConnection conn = new SqlConnection(connString))
  {
      conn.Open();
  
      List&lt;int&gt; integers = new List&lt;int&gt;{ 1, 2, 3 };
      List&lt;string&gt; strings = new List&lt;string&gt; { "A", "B", "C" };
  
      var parameters = new {str = strings, integer = integers };
  
      //fails here
      IEnumerable&lt;string&gt; intTest = conn.Query&lt;string&gt;(sqlIntegerIn, parameters, commandType: System.Data.CommandType.Text);
  
      //and here
      IEnumerable&lt;string&gt; stringTest = conn.Query&lt;string&gt;(sqlStringIn, parameters, commandType: System.Data.CommandType.Text);
  
  }
  </code></pre>