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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:42:06+00:00 2026-06-05T15:42:06+00:00

How would I reverse contains in a Linq-to-SQL query so that I can check

  • 0

How would I reverse contains in a Linq-to-SQL query so that I can check if Title or Description contain any word from my list, something like:

var query = context.Shapes.Where(x => x.Title.Contains(words));

Here is what I have now but that is opposite from what I need.

 List<string> words = Search.GetTags(q);
 //words = round,circle,square

 using(ShapesDataContext context = new ShapesDataContext())
 {
    var query = context.Shapes.Where(x => words.Contains(x.Title) || 

    words.Contains(x.Description));
 }

// Item 1: Title = Elipse , Decsription = This is not round circle
//This should be a match! but words doesn't contain 
//"This is not round circle", only round and circle so no match

UPDATE

Now I have

  var query = context.Shapes.Where(x => words.Any(w => x.Title.Contains(w) || x.Description.Contains(w)))
  int s = query.Count();

but now I get exception on int s = query.Count(); with message “Local sequence cannot be used in LINQ to SQL implementations of query operators except the Contains operator.” Does anyone know how to solve it?

  • 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-05T15:42:08+00:00Added an answer on June 5, 2026 at 3:42 pm

    Not the most efficient but I managed:

     List<string> words = Search.GetTags(q);
     using(ShapesDataContext context = new ShapesDataContext())
     {
       IQueryable<Shape> query = Enumerable.Empty<Shape>().AsQueryable();
       foreach (var word in words)
       {
         query = query.Union(context.Shapes.Where(x => x.Title.Contains(word) || x.Description.Contains(word)));
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would I do in a SELECT query to reverse this path : z/y/x
I have an application that I have behind a reverse proxy, I would like
I would like to build a small python script that basicaly does the reverse
I have a table that contains some sensitive data that I would like to
I have a large (100+ tables) SQL Server 2005 database that I would like
I asked the question here and now i would like to reverse this procedure
Would it be possible to add a new operator to the String class that
I'm wondering if it is bad practice to have a reverse proxy that selects
I have a list of ID numbers that I pull from a session variable
Here's my quandary. I have a variable that contains a paragraph of text, and

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.