Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 130965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:01:52+00:00 2026-05-11T06:01:52+00:00

I have a List <string > of variable count, and I want to query

  • 0

I have a List<string> of variable count, and I want to query (via LINQ) a table to find any items that contain any of those strings in the Text column.

Tried this (doesn’t work):

items = from dbt in database.Items          where (stringList.FindAll(s => dbt.Text.Contains(s)).Count > 0)          select dbt; 

Query would be something like:

select * from items where text like '%string1%' or text like '%string2%' 

Is this possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T06:01:52+00:00Added an answer on May 11, 2026 at 6:01 am

    Check this article out to do what you want:
    http://www.albahari.com/nutshell/predicatebuilder.aspx

    This works like a dream. I essentially cut and pasted their code and got this back (with my own data-scheme of course):

    SELECT [t0].[Id], [t0].[DateCreated], [t0].[Name] ... FROM [dbo].[Companies] AS [t0] WHERE ([t0].[Name] LIKE @p0) OR ([t0].[Name] LIKE @p1) 

    Here is the code I ran for the proof of concept:

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions;  namespace PredicateTest { class Program {     static void Main(string[] args)     {         DataClasses1DataContext dataContext = new DataClasses1DataContext();          Program p = new Program();         Program.SearchCompanies('test', 'test2');         var pr = from pi in  dataContext.Companies.Where(Program.SearchCompanies('test', 'test2')) select pi;     }      DataClasses1DataContext dataContext = new DataClasses1DataContext();      public static Expression<Func<Company, bool>> SearchCompanies(                                                   params string[] keywords)     {         var predicate = PredicateBuilder.False<Company>();         foreach (string keyword in keywords)         {             string temp = keyword;             predicate = predicate.Or(p => p.Name.Contains(temp));         }         return predicate;     }  }  public static class PredicateBuilder {     public static Expression<Func<T, bool>> True<T>() { return f => true; }     public static Expression<Func<T, bool>> False<T>() { return f => false; }      public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> expr1,                                                         Expression<Func<T, bool>> expr2)     {         var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());         return Expression.Lambda<Func<T, bool>>               (Expression.OrElse(expr1.Body, invokedExpr), expr1.Parameters);     }      public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> expr1,                                                          Expression<Func<T, bool>> expr2)     {         var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());         return Expression.Lambda<Func<T, bool>>               (Expression.AndAlso(expr1.Body, invokedExpr), expr1.Parameters);     } } } 

    I’d suggest going to the site for the code and explanation.

    (I am leaving the first answer because it works well if you need an IN statement)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code that generates a List<string[]> variable but can't quite figure out how
I have a variable that can either contain a list of strings or a
I have a list of string values that I want add to a hashtable
I have a list: List(Of String) I want to filter it with LINQ. I
I have a List of String objects that are pipe delimited. something like this:
I have a list of string like: s = [(abc,bcd,cde),(123,3r4,32f)] Now I want to
I have a list of string that I am writing out to a CSV
I have a String List with items like this Root Root/Item1 Root/Item2 Root/Item3/SubItem1 Root/Item3/SubItem2
I have List[(String,String)] and I need to sort them by the 2nd value and
I have a list like this Dim emailList as new List(Of String) emailList.Add(one@domain.com) emailList.Add(two@domain.com)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.