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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:11:53+00:00 2026-05-15T20:11:53+00:00

How can I combine two lambda expressions into one using an OR ? I

  • 0

How can I combine two lambda expressions into one using an OR ?

I have tried the following but merging them requires me to pass parameters into the Expression.Invoke calls, however I want the value passed into the new lambda to be passed onto each child-lambda..

Expression<Func<int, bool>> func1 = (x) => x > 5;
Expression<Func<int, bool>> func2 = (x) => x < 0;
//Combines the lambdas but result in runtime error saying I need to pass in arguments
//However I want the argument passed into each child lambda to be whatever is passed into the new main lambda
Expression<Func<int, bool>> lambda = Expression.Lambda<Func<int, bool>>(Expression.Or(Expression.Invoke(func1), Expression.Invoke(func2)));

 //The 9 should be passed into the new lambda and into both child lambdas
 bool tst = lambda.Compile().Invoke(9);

Any ideas how to combine two lambda expressions into one and have the arguments of the child lambdas be that of the parent ?

  • 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-15T20:11:54+00:00Added an answer on May 15, 2026 at 8:11 pm

    The best way I found to learn expressions, is to take a look at the source code of PredicateBuilder.

    When you want to combine multiple your statements, you can:

    Expression<Func<int, bool>> func1 = (x) => x > 5;
    Expression<Func<int, bool>> func2 = (x) => x > 10;
    
    var invocation = Expression.Invoke(func2, func1.Parameters.Cast<Expression>());
    var expression = Expression.Lambda<Func<int, bool>>(Expression.OrElse(func1.Body, invocation), func1.Parameters);
    

    The Expression.Invoke creates an InvocationExpression that applies the parameters to your func2.

    In fact, PredicateBuilder may be everything you need.

    var predicate = PredicateBuilder.False<int>();
    predicate = predicate.Or(x => x > 5);
    predicate = predicate.Or(x => x > 10);
    

    I would revise “x > 5 or x > 10“, seems like an odd thing to OR.

    Hope that helps.

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

Sidebar

Ask A Question

Stats

  • Questions 509k
  • Answers 509k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Generally speaking, you will build a full site with Rails,… May 16, 2026 at 4:40 pm
  • Editorial Team
    Editorial Team added an answer Yes. Here's a workaround: When does browser automatically clear cache… May 16, 2026 at 4:40 pm
  • Editorial Team
    Editorial Team added an answer try this: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html… May 16, 2026 at 4:40 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Can I combine these two blocks into one: Edit: Any other method than combining
How can you combine two windows in Screen? I have two windows such that
im trying to combine two images into a single image. unfortunately this has to
How can i combine two arrays in to a single array during compound selection
Can someone tell me how I can combine the two SQL statements that count
How can I merge/combine two or three elements of a list. For instance, if
I have two UIImage objects as follow: image1: image2: I wish to combine the
I'm trying to update two fields of several rows at once but I can't
I am using two different jQuery plugins that I'm trying to combine. First I'm
I have an extension method with the following signature: public static Expression<Func<T, bool>> And<T>(this

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.