title: How do I use the SQL WHERE IN construct with PetaPoco?
body: <p>I have a database table named Tags (Id, Name) from which I would like to select the ones where the name matches a name in a list. In SQL I would use something like:</p>
  
  <pre><code>Select * from Tags Where Name In ('Name1', 'Name2', 'xxx...)
  </code></pre>
  
  <p>But now using PetaPoco in an ASP.Net MVC3 project I'm stuck figuring out how to do it properly. So far I've tried:</p>
  
  <pre><code>var tagsToFind = new string[] { "SqlServer", "IIS" };
  var sql = PetaPoco.Sql.Builder.Select("*").From("Tags").Where("Name in (@0)", tagsToFind);
  var result = db.Query&lt;Tag&gt;(sql);
  </code></pre>
  
  <p>Which results in the following SQL, where <strong>only the first</strong> name in my list of tagsToFind is used to match the table data as opposed to all of them.</p>
  
  <pre><code>SELECT * FROM Tags WHERE (Name in (@0)) -&gt; @0 [String] = "SqlServer"
  </code></pre>
  
  <p>It's a little frustrating, knowing this probably isn't so hard.. any help is appreciated!</p>
  
  <p><strong>Update:</strong>
  I found out that it can be done in another way</p>
  
  <pre><code>var sql = PetaPoco.Sql.Builder.Append("Select * from tags Where Name IN (@0", tagNames[0]);
  foreach (string tagName in tagNames.Where(x =&gt; x != tagNames[0])) {
      sql.Append(", @0", tagName);
  }        
  sql.Append(")");
  var result = db.Query&lt;Tag&gt;(sql)
  </code></pre>
  
  <p>which gets me what I want while using sqlparameters. So I guess it's good enough for now, although not super pretty.</p>
  
  <p>/Mike</p>