title: linq return all items where string field is like any in a list of strings
body: <p>I have a SQL table storing all enquiries on my site. the database isn't normalized and destinations of the site are stored as a comma separated variable based on the ID of the country they want to go to.</p>
  
  <p>I've used LINQ to get a list of all country ID's deemed as 'close'. I'd then like to use that in linq to get all enquiries where the CSV contains any of those country ID's.</p>
  
  <p>so for example my countries may be stored as a list <code>6 | 20 | 24</code></p>
  
  <p>and i would like to return all enquiries where the CSV value has any of those values in it. so if the CSV value was <code>'18,54,23,27,6'</code> then it would return that enquiry. My main problem is because this value is stored as a string in the table, so any comparison looking for a part of that string is unavaliable. If it were SQL directly i would type <code>where Destinations like('%6%')</code>.Repeated for each example in the list.</p>
  
  <p>I have had a go, and it isn't working.</p>
  
  <ul>
  <li><p><code>Dim count As Integer = ctx.tbl_Enquiries.Where(Function(f) f.Destinations.Contains(shorthaulIds.Any())).Count</code> I tried this, but It compares against the whole destination CSV. rather than looking for a string within the string.</p></li>
  <li><p>I tried turning the csv to a list on the fly, which obviously wont work as string functions in linq tend not to work. - if you're interested in that then 
  <code>Dim count As Integer = ctx.tbl_Enquiries.SelectMany(Function(f) f.Destinations.Split(",").Where(Function(fe) fe.Split("c").Contains(shorthaulIds.Any()))).Count</code></p></li>
  </ul>
  
  <p>I also tried some intersects, but as I hadnt used them before I wasn't really sure what I was doing</p>
  
  <h3>for c# users</h3>
  
  <ul>
  <li><code>int count = ctx.tbl_Enquiries.Where(f =&gt; f.Destinations.Contains(shorthaulIds.Any())).Count</code> </li>
  </ul>