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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:19:09+00:00 2026-05-13T21:19:09+00:00

consider the following code, which represents an attempt to implement partial matching. the intended

  • 0

consider the following code, which represents an attempt to implement partial matching. the intended result is a row for any 1 or more fields that match between the query entity and the data store.

so if you supply person.email we want a match against that, if you supply person.email and person.FirstName we should filter the results further, and so on.

        var results = from p in db.Persons
                      where p.CrookBookUserName.Trim().Contains(person.CrookBookUserName.Trim()) ||
                      p.email.Trim().Contains(person.email.Trim()) ||
                      p.FirstName.Trim().Contains(person.FirstName.Trim()) ||
                      p.LastName.Trim().Contains(person.LastName.Trim()) ||
                      p.phone.Trim().Contains(person.phone.Trim())
                      select p;

        return results;

unfortunately, this code always returns all rows in the db. why, and what should be the fix?

thanks in advance.

  • 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-13T21:19:10+00:00Added an answer on May 13, 2026 at 9:19 pm

    Does person have all fields populated? A p.email.Trim().Contains("") from an empty email address will return true for everything.

    An extra (!String.IsNullOrEmpty(..)) && before each parameter, while verbose, will fix it if this is the problem.

    Edit re comments:

    Yeah, a helper method or something could help here… something like

    public static bool ContainsIfNotEmptyTrimmed(this string source, string param)
    {
        return !String.IsNullOrEmpty(param.Trim()) && source.Trim().Contains(param.Trim());
    }
    
    where p.CrookBookUserName.ContainsIfNotEmptyTrimmed(person.CrookBookUserName) || ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code which is typcial of many ChannelFactory examples: WSHttpBinding myBinding =
Consider the following code which shows compile time error : #include <stdio.h> int main(int
Consider the following code which is to be thrown at an AR find: conditions
Consider the following sample code which uses a TrustManager to log whether an outgoing
I've got some basic questions about C++. Consider the following code in which I
I have a relatively simple use case which is failing. Consider the following code:
Consider the following code which uses non-blocking semantics to pop a stack: T Stack<T>::pop(
Consider the following imperative code which finds the largest palindrome among products of 3-digit
Consider the following code which does not rollback the transaction if an exception is
Consider the following code: $(a).attr(disabled, disabled); In IE and FF, this will make anchors

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.