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

  • Home
  • SEARCH
  • 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 9049451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:24:07+00:00 2026-06-16T12:24:07+00:00

I am working on a (quick and dirty) search engine, using linq to sql.

  • 0

I am working on a (quick and dirty) search engine, using linq to sql. I already have a table of strings containing each word I want to search inside the descriptions of each entry.

In the end of my linq to sql process, I should get only the entries containing all the words from my table. Here is the code I have so far (m1 is my table of strings) :

var myUser = from u in dataBase.Profiles
             where u.Status == 2 // some primary selection
             select u;
foreach (string word in m1)
{
  myUser = from u in myUser
           where ((word != "") ? u.Description.Contains(word) : 1 == 1)
           select u;
}
myUser = from u in myUser
         orderby u.ModificationDate descending // finally, we order the list
         select u;

This code works nicely, but sadly, it does not select entries containing both words, but all the entries containing at least one word.

Can you understand why? I don’t : /

  • 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-16T12:24:08+00:00Added an answer on June 16, 2026 at 12:24 pm

    You are closing over the loop variable.

    Closures close over variables, not over values.

    Try assigning the string to a local variable:

    foreach (string word2 in m1)
    {
        string word = word2;
        myUser = from u in myUser
               where ((word != "") ? u.Description.Contains(word) : 1 == 1)
               select u;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working with JQuery Validator and just have a quick question. I'm using addMethod to
I'm working on a very, very quick and dirty application using almost entirely scaffold
Hey everyone, just a quick thing, I have the hex to integer working, but
I am working on a quick and dirty script to get Chromium's bookmarks and
I have a quick question now I am working with timers in EJB and
In a quick-and-dirty Perl script, I have a data structure like this: $tax_revenue{YEAR}{STATE}{GOVLEV}{TAX} =
I'm working on a python plugin for Google Quick Search Box, and it's doing
Can someone please help me understand why this code is not working? $('#quick-search-header.widget-title').css('background-image', 'url(dd_includes/images/icons/sliding-menu-arrow-right.gif)');
I am working on quick project , listing search results from bing and my
I have been working on a quick WinForms program. I found this SO question

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.