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 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

Related Questions

Is there any way I can combine list of expressions into one? I have
Can I combine these two blocks into one: Edit: Any other method than combining
I have the following. Is there some way that I can combine these two
How I can combine two image maps? I have the following areas ... <area
Is there any way that you can combine two shapes into one, not geometries.
How can I combine those two queries into one? 1) This finds the japanese
How can you combine two windows in Screen? I have two windows such that
Can I combine these two SQL queries into single query? query1 ALTER TABLE tableA
I have two lambda expressions: Expression<Func<MyEntity, bool>> e1 = i = >i.FName.Contain(john); and Expression<Func<MyEntity,
I know you can combine multiple table-selects using a Join statement but is there

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.