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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:41:13+00:00 2026-05-16T17:41:13+00:00

Can you help me with next: I’d like to add variable count of SqlMethods.Like()

  • 0

Can you help me with next: I’d like to add variable count of SqlMethods.Like() in one query?

For example: I’ve four words in list catCode, how can I create LINQ query with four SqlMethods.Like()?

using (var db = new MappingDataContext(_connection))
{
    db.ObjectTrackingEnabled = false;

    return (
        from r in db.U_CDW_REPORTs
        where (catCode.Length > 0 ? 
            SqlMethods.Like(r.CATEGORY, catCode) : r.CATEGORY != "*")
        where r.SI_QTY > 0
        orderby r.SI_QTY descending
        select new Item
        {
            ...
        }).ToList();
}
  • 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-05-16T17:41:13+00:00Added an answer on May 16, 2026 at 5:41 pm

    What you need is dynamically OR-ing SqlMethod.Like operations. You need the PredicateBuilder.


    Update: Here is an example of how to use the predicate builder.

    string[] searchItems =
        new string[] { "Pattern1", "Pattern2", "Pattern3" };
    
    var likeExpression = PredicateBuilder.False<U_CDW_REPORT>();
    
    foreach (string searchItem in searchItems)
    {
        var searchPattern = "%" + searchItem + "%";
        likeExpression = likeExpression.Or(r => 
            SqlMethods.Like(r.CATEGORY, searchPattern));
    }
    
    return (
        from r in db.U_CDW_REPORTs.Where(likeExpression)
        where r.SI_QTY > 0
        orderby r.SI_QTY descending
        select new Item { ... }).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wondering if you can help me position two divs, mainContent and sideContent next
Wondering if anyone can help me. I'm trying to put together a weekly photo
I have attempted this is many ways but failed consistently, hopefully you can help
When developing on BlackBerry or iOS, you can deploy your application just by dropping
I've got an expandable css menu that is acting a bit weird in ie,
Wondering if I'm going about this the right way or not. I have 3
I'm pretty new to Objective C but things are progressing well. However, I think
I'm developing a new app and i need to implement a functionality used very
I don't profess to be any master of Excel, so when these things arrive

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.