title: Why are my bound parameters all identical (using Linq)?
body: <p>When I run this snippet of code:</p>
  
  <pre><code>string[] words = new string[] { "foo", "bar" };
  var results = from row in Assets select row;
  foreach (string word in words)
  {
      results = results.Where(row =&gt; row.Name.Contains(word));
  }
  </code></pre>
  
  <p>I get this SQL:</p>
  
  <pre><code>-- Region Parameters
  DECLARE @p0 VarChar(5) = '%bar%'
  DECLARE @p1 VarChar(5) = '%bar%'
  -- EndRegion
  SELECT ... FROM [Assets] AS [t0]
  WHERE ([t0].[Name] LIKE @p0) AND ([t0].[Name] LIKE @p1)
  </code></pre>
  
  <p>Note that <code>@p0</code> and <code>@p1</code> are both <code>bar</code>, when I wanted them to be <code>foo</code> and <code>bar</code>.  </p>
  
  <p>I guess Linq is somehow binding a reference to the variable <code>word</code> rather than a reference to the string currently referenced by <code>word</code>?  What is the best way to avoid this problem?</p>
  
  <p>(Also, if you have any suggestions for a better title for this question, please put it in the comments.)</p>
  
  <p>Note that I tried this with regular Linq also, with the same results (you can paste this right into Linqpad):</p>
  
  <pre><code>string[] words = new string[] { "f", "a" };
  string[] dictionary = new string[] { "foo", "bar", "jack", "splat" };
  var results = from row in dictionary select row;
  foreach (string word in words)
  {
      results = results.Where(row =&gt; row.Contains(word));
  }
  results.Dump();
  </code></pre>
  
  <p>Dumps:</p>
  
  <pre><code>bar
  jack
  splat
  </code></pre>