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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:54:45+00:00 2026-05-30T03:54:45+00:00

I am using predicates to refine search options and am getting two different results

  • 0

I am using predicates to refine search options and am getting two different results when i run what looks to be the same query.

This one is correct and returns the expected results:(hard coded strings)

_predicate = PredicateBuilder.False<TBLDESIGN>();
_predicate = _predicate.Or(a => a.IS_APPROVED == true & a.ACTIVE == true & a.DATE_APPROVED > beginDate & (a.KEYWORDS.Contains("red") || a.NAME.Contains("red")));
_predicate = _predicate.Or(a => a.IS_APPROVED == true & a.ACTIVE == true & a.DATE_APPROVED > beginDate & (a.KEYWORDS.Contains("geos") || a.NAME.Contains("geos")));

This one only returns the results from the second predicate “geos”. The first one in the loop(“red”) is ignored. Values “red” and “geos” are inside the loop below.

string searchTerm = "";
_predicate = PredicateBuilder.False<TBLDESIGN>();
for (int i = 0; i < search.Count(); i++)
{
    searchTerm = search[i].SearchTerm.Trim().ToString();
    _predicate = _predicate.Or(a => a.IS_APPROVED == true & a.ACTIVE == true & a.DATE_APPROVED > beginDate & (a.KEYWORDS.Contains(searchTerm) || a.NAME.Contains(searchTerm)));
}

Here is the rest of the query if that makes any difference.

            var results =
                        dbContext.TBLDESIGN
                        .Include(s => s.LKPRICE)
                        .Include(s => s.TBLDESIGNER)
                        .AsExpandable().Where(_predicate)
                        .OrderByDescending(s => s.DATE_APPROVED)
                        .Select(s => new
                        {
                            s.ACTIVE,
                            s.DATE_CREATED,
                            s.EXPORTED,
                            s.IMAGE_PATH,
                            DesignId = s.ID,
                            s.IS_APPROVED,
                            s.TBLDESIGNER.FIRST_NAME,
                            s.TBLDESIGNER.LAST_NAME,
                            s.TBLDESIGNER.ALIAS,
                            s.NAME,
                            s.LKPRICE.PRICE,
                            s.COMPLETED,
                            s.DATE_APPROVED,
                            DesignerId = s.TBLDESIGNER.ID,
                            s.VIEW_COUNT
                        }).ToList();

Question is how to get the second list of predicates to return the same results as the first series. Guessing there is something extra to do when you are passing a string variable in rather than a hard coded value.

Thanks,
Billy

Answer:

_predicate = PredicateBuilder.False<TBLDESIGN>();
for (int i = 0; i < search.Count(); i++)
{
    string searchTerm = search[i].SearchTerm.Trim().ToString();
    _predicate = _predicate.Or(a => a.IS_APPROVED == true & a.ACTIVE == true & a.DATE_APPROVED > beginDate & (a.KEYWORDS.Contains(searchTerm) || a.NAME.Contains(searchTerm)));
}
  • 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-30T03:54:47+00:00Added an answer on May 30, 2026 at 3:54 am

    string declaration needs to occur inside of the loop.

    _predicate = PredicateBuilder.False<TBLDESIGN>();
        for (int i = 0; i < search.Count(); i++)
        {
            string searchTerm = search[i].SearchTerm.Trim().ToString();
            _predicate = _predicate.Or(a => a.IS_APPROVED == true & a.ACTIVE == true & a.DATE_APPROVED > beginDate & (a.KEYWORDS.Contains(searchTerm) || a.NAME.Contains(searchTerm)));
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to rewrite this, maybe using predicates, or Lambda, how can I do
I'm building a LINQ query using a loop that appends predicates using an array:
I am very new to using predicates and just learned how to write: Predicate<int>
I have this grammar to match simple logical predicates in ANTLR. exp : or
Certain kinds of domain logic are represented more naturally using Prolog predicates than C#
I'm testing out the PostgreSQL Text-Search features, using the September data dump from StackOverflow
I have the same issue using hibernate against DB2 and MySQL. Here is a
Suppose i have a one to many relationship between two model entities Entity One
What is the best way to do a conditional query using linq to objects(not
Using only these predicates..... child(X) X is a child unwell(X,Y) X is unwell on

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.