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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:56:57+00:00 2026-06-10T11:56:57+00:00

I need a Linq statement that will select all from a table where a

  • 0

I need a Linq statement that will select all from a table where a field contains all elements in a list<String> while searching other fields for the entire string regardless of words.

It’s basically just a inclusive word search on a field where all words need to be in the record and string search on other fields.

Ie I have a lookup screen that allows the user to search AccountID or Detail for the entire search string, or search clientID for words inclusive words, I’ll expand this to the detail field if I can figure out the ClientId component.

The complexity is that the AccountId and Detail are being searched as well which Basically stops me from doing the foreach in the second example due to the "ors".

Example 1, this gives me an the following error when I do query.Count() afterwards:

query.Count(); ‘query.Count()’ threw an exception of type ‘System.NotSupportedException’ int {System.NotSupportedException}

+base {"Local sequence cannot be used in LINQ to SQL implementations of query operators except the Contains operator."} System.SystemException {System.NotSupportedException}

var StrList = searchStr.Split(' ').ToList();

query = query.Where(p => p.AccountID.Contains(searchStr) || StrList.All(x => p.clientID.Contains(x)) || p.Detail.Contains(searchStr));

Example 2, this gives me an any search word type result:

var StrList = searchStr.Split(' ').ToList();
  foreach (var item in StrList)
    query = query.Where(p => p.AccountID.Contains(searchStr) || p.clientID.Contains(item) || p.Detail.Contains(searchStr));

Update

I have a table with 3 fields, AccountID, ClientId, Details

Records
Id, AccountID, CLientId, Details

1, "123223", "bobo and co", "this client suxs"

2, "654355", "Jesses hair", "we like this client and stuff"

3, "456455", "Microsoft", "We love Mircosoft"

Search examples

searchStr = "232"
Returns Record 1;

searchStr = "bobo hair"
Returns no records

searchStr = "bobo and"
Returns Record 1

searchStr = "123 bobo and"
Returns returns nothing

The idea here is:

  • if the client enters a partial AccountId it returns stuff,
  • if the client wants to search for a ClientId they can type and cancel down clients by search terms, ie word list. due to the large number of clients the ClientID Will need to contain all words (in any order)

I know this seems strange but it’s just a simple interface to find accounts in a powerful way.

  • 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-10T11:56:58+00:00Added an answer on June 10, 2026 at 11:56 am

    I think there are 2 solutions to your problem.

    One is to count the results in memory like this:

    int count = query.ToList().Count();
    

    The other one is to not use All in your query:

    var query2 = query;
    foreach (var item in StrList)
    {
        query2 = query2.Where(p => p.clientID.Contains(item));
    }
    var result = query2.Union(query.Where(p => p.AccountID.Contains(searchStr) || p.Detail.Contains(searchStr)));
    

    The Union at the end acts like an OR between the 2 queries.

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

Sidebar

Related Questions

I need a linq statement that returns all entries from a certain date. A
I need to replicate a T-SQL statement that has an inner select, using LINQ:
Consider the database schema in the picture. I need a linq-to-entities statement that will
I have a linq statement that returns a list of <string,string> key value pairs.
I am using a LINQ statement that selects from various tables information I need
I have a LINQ statement that returns an anonymous type. I need to get
I have a statement similar to this that I need to run in Linq.
I need to write the following SQL statement in LINQ lambdas : SELECT *
I need to gather Distinct Id's from a particular table using LINQ. The catch
I need to create a Linq query that would have the following logic: IEnumerable<string>

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.