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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:06:30+00:00 2026-06-01T21:06:30+00:00

I have experimented with 2 forms of the call, this one products = DocumentSession.Query<Product>()

  • 0

I have experimented with 2 forms of the call, this one

 products = DocumentSession.Query<Product>()
      .Statistics(out stats)
      .Where(p => p.INFO2.StartsWith(term1))
      .Where(p => p.INFO2.StartsWith(term2))
      .Where(p => p.INFO2.StartsWith(term3)) 
      .OrderByField(columnToSortBy, columnToSortByAsc)
      .Skip(pageIndex * pageSize)
      .Take(pageSize)
      .ToList()
      ;

and this way

  products = DocumentSession.Query<Product>()
      .Statistics(out stats)
      .Where(p => p.INFO2.StartsWith(term1) & p.INFO2.StartsWith(term2) & p.INFO2.StartsWith(term3))
      .OrderByField(columnToSortBy, columnToSortByAsc)
      .Skip(pageIndex * pageSize)
      .Take(pageSize)
      .ToList()
      ;

The first one returns records that are more in-line with my expectations, while the seconds seems to return ALL documents of type Product. What are the differences between the 2 from a LINQ expression point of view, and have I overlooked anything that might negate what I am trying to accomplish, which is a 3 term query and each term being AND’d together.

EDIT: revised code per Russ.

  string t1 = terms[0];
  string t2 = terms[1];
  string t3 = terms[2];

  products = DocumentSession.Query<Product>()
      .Statistics(out stats)
      .Where(p => p.INFO2.StartsWith(t1) && p.INFO2.StartsWith(t2) && p.INFO2.StartsWith(t3)) 
      .OrderByField(columnToSortBy, columnToSortByAsc)
      .Skip(pageIndex * pageSize)
      .Take(pageSize)
      .ToList()
      ;

EDIT 2: This is where you smash your face down on the keyboard, or any other solid object for that matter… Gotta get back to the basic here with standard C# And and Or

Thank you,
Stephen

  • 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-01T21:06:31+00:00Added an answer on June 1, 2026 at 9:06 pm

    In the second block you’re doing an & instead of an && so instead of being an AND comparison, it’s trying to do a bitwise operation.

    Edit: in the 2nd case, you can change this:

    .Where(p => p.INFO2.StartsWith(terms[0]) & p.INFO2.StartsWith(terms[1]) & p.INFO2.StartsWith(terms[2]))
    

    to this:

    .Where(p => p.INFO2.StartsWith(terms[0]) && p.INFO2.StartsWith(terms[1]) && p.INFO2.StartsWith(terms[2]))
    

    Which makes it proper AND clause.

    2nd edit: If this is meant to be an AND operation, then you don’t need 3 terms – you need a single term, otherwise you’ll be comparing against 3 instances of the same string.

    terms[0] = "test";
    terms[1] = "test";
    terms[2] = "test";
    
    .Where(p => p.INFO2.StartsWith(terms[0]) && p.INFO2.StartsWith(terms[1]) && p.INFO2.StartsWith(terms[2]))
    

    Is the same as

    string term = "test";
    
    .Where(p => p.INFO2.StartsWith(term) && p.INFO2.StartsWith(term) && p.INFO2.StartsWith(term))
    

    Just mentioning this as this may make your code harder to maintain in the future.

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

Sidebar

Related Questions

I have experienced some memory managment ambiguitys with opencv. You could do this with
I have been looking all over the Internet for an answer to this question
Alright, I presented this question on the MSDN forums but have yet to receive
This one is a long one, bellow is my primary class that holds the
I have a C# windows forms application which communicates with a USB dongle via
This is probably trivial, and I do have a solution but I'm not happy
Have you experimented with single page web application, i.e. where the browser only 'GETs'
I have a PHP script like this: <?php include 'authorization_script.php'; foreach ($_POST as $key
I have tried to include a partial into a modal something similar to this
This one just stabbed me hard. I don't know if it's the case with

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.