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 8310017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:18:33+00:00 2026-06-08T19:18:33+00:00

I need to create a function that receives a list of strings, and returns

  • 0

I need to create a function that receives a list of strings, and returns a list of all the items that match (i.e., SQL “LIKE”, case-insensitive and ignoring diacritics):

// Pseudocode example
IEnumerable<Item> Search(List<String> patterns)
{
    var result = new List<Item>();

    foreach (var Item in context.Items)
    {
        bool matches = true;

        foreach (var pattern in patterns)
        {
            if (!Item.Name.Contains(pattern))
            {
                matches = false;
                break;
            }
        }

        if (matches)
        {
            result.Add(Item);
        }
    }

    return result;
}

While something similar to this works, it’s less than ideal (it seems horribly inefficient).

Is it possible to create a (possibly LINQ) query that generates something similar to the following SQL?:

SELECT *
FROM items
WHERE items.name LIKE :pattern1
  AND items.name LIKE :pattern2
  ...
  AND items.name LIKE :patternN
  • 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. Editorial Team
    Editorial Team
    2026-06-08T19:18:34+00:00Added an answer on June 8, 2026 at 7:18 pm

    You can simply iterate your patterns and apply a WHERE clause for each.

    var patterns = new List<string>();
    using (var context = new MyDataContext())
    {
        var query = (IQueryable<Area>)context.Areas;
    
        foreach (var pattern in patterns)
        {
            query = query.Where(a => a.Description.Contains(pattern));
        }
    
        return query.ToList();
    }
    

    As you probably know, the query is lazy-executed, and in this case won’t be executed until the ToList call after all patterns are applied.

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

Sidebar

Related Questions

I need to create a function that receives a string and checks if the
i am trying to create sql procedure or function that need to find duplicate
I want to create a function that receives 2 arguments and returns a function
I want to create a function that receive multiples strings as parameters. Like the
I need to create a function that uses a loop. This function will open
I need to create a function that, among other things, spawns a child process.
I need to create a function that takes month and year as parameters and
I need to create a javascript function that checks if it has been a
I need to create a function which rounds decimal numbers like this: Round($32.95, 0)
i need to create a function that will accept a directory path. But in

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.