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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:53:46+00:00 2026-06-08T08:53:46+00:00

We have a form which allows users to specify criteria to query a database.

  • 0

We have a form which allows users to specify criteria to query a database.

Our form builds “criterion” objects which are then used to build the nHibernate criteria.

Our current code to do this is:

public virtual ICriteria BuildCriteria(ICriteria criteria)
{
    foreach (SheCriterion criterion in this.SheCriterions)
    {
        if (criterion.OperatorKey == "OR")
        {
            //// code required here to process ORs
        }
        criteria.Add(criterion.BuildCriterion());
    }
    return criteria;
}

Unfortunately, this is where I’m stuck – if we AND each criterion there is no problem but I’m having difficulties in working out how to add ORs – by the time we know that an OR is involved, the previous criterion has already been processed.

Can anyone help?

  • 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-08T08:53:49+00:00Added an answer on June 8, 2026 at 8:53 am

    or is not that easy. Consider a and b or c there are 2 different possibilities (a and b) or c and a and (b or c) so if a = false you’ll get two different answers. You’ll have to build a tree of criterias and in

    public virtual ICriteria BuildCriteria(ICriteria criteria)
    {
        foreach (SheCriterion criterion in this.SheCriterions)
        {
            criteria.Add(criterion.BuildCriterion());
        }
    
        return criteria;
    }
    
    public virtual ICriterion BuildCriterion()
    {
        if (OperatorKey == "OR")
        {
            return new Disjunction()
                .Add(Left.BuildCriterion())
                .Add(right.BuildCriterion());
        }
        else
        {
            return new Conjunction()
                .Add(Left.BuildCriterion())
                .Add(right.BuildCriterion());
        }
    }
    

    Update: you’ll need a tree otherwise

    Man { Name = "Bill", Eyecolor = "blue", Height = 175, IsRich = true };
    
    // will show Bill
    SELECT * FROM Men WHERE height > 180 AND eyecolor = blue OR IsRich = 1
    SELECT * FROM Men WHERE (height > 180 AND eyecolor = blue) OR IsRich = 1
    
    // will not show Bill
    SELECT * FROM Men WHERE height > 180 AND (eyecolor = blue OR IsRich = 1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm have a form set up which allows users to register with our mobile
Say I have a form that allows users to upload multiple images, which are
I have a form which allows users to comment on a page, however they
I have a form that allows users to view some terms and conditions, which
I have a TMemo on a form which allows users to enter a list
In my website, I have a form which allows users to post an image
I have a form which allow users to choose the type of permit they
I have a HTML form which allows a user to add rows ad hoc
I have this form which allows the input of any product quantity from 1-10:
The website has a normal registration form which allows users to register and the

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.