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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:59:00+00:00 2026-05-16T08:59:00+00:00

I have two expression trees defined like this: private Expression<Func<TEntity, TPropertyResult>> PropertyAccessor { get;

  • 0

I have two expression trees defined like this:

private Expression<Func<TEntity, TPropertyResult>> PropertyAccessor { get; set; }

and

private Expression<Func<TPropertyResult, bool>> TestExpression { get; set; }

I need to create a new expression tree that will result in the equivalent of:

var expression = p => this.TestExpression(this.PropertyAccessor(p));

When using Expression.Invoke(this.TestExpression, this.PropertyAccessor), I get the following error

{“Expression of type
‘System.Func`2[MyEntity,System.String]’
cannot be used for parameter of type
‘System.String'”}

TPropertyResult is a string during my test.

I tried using Expression.Call or Expression.Invoke. No luck. What should I use?

  • 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-16T08:59:01+00:00Added an answer on May 16, 2026 at 8:59 am

    I think this does what you are asking for:

    Expression<Func<TEntity, bool>> Combined
    {
        get
        {
            var entity = Expression.Parameter(typeof(TEntity));
            var pa = Expression.Invoke(PropertyAccessor, entity);
            var te = Expression.Invoke(TestExpression, pa);
            return (Expression<Func<TEntity, bool>>) Expression.Lambda(te, entity);
        }
    }
    

    I tested this and it works as I would expect.

    However, re-reading your original question (before my edits), I am beginning to get the impression that you asked the wrong question and that you probably don’t need expression trees. If all you need is functions, then you can use them without Expression:

    private Func<TEntity, TPropertyResult> PropertyAccessor { get; set; }
    private Func<TPropertyResult, bool> TestExpression { get; set; }
    private Func<TEntity, bool> Combined
    {
        get
        {
            return entity => TestExpression(PropertyAccessor(entity));
        }
    }
    

    Example of use:

    // Set up the original functions
    PropertyAccessor = entity => GenerateResult(entity);
    TestExpression = result => result.IsCool();
    
    // This stores a reference to the combined function
    var fn = Combined;
    
    // This actually evaluates the function
    bool isCool = fn(myEntity);
    
    // Alternatively, you could evaluate the function directly, without the variable
    bool isCool = Combined(myEntity);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two lambda expressions: Expression<Func<MyEntity, bool>> e1 = i = >i.FName.Contain(john); and Expression<Func<MyEntity,
I have two expressions: public static Expression<Func<int, bool>> IsDivisibleByFive() { return (x) => x
I have two expressions of type Expression<Func<T, bool>> and I want to take to
I have two Classes : class Customer { public string Fullname { get; set;
I have complex logical expression that look like this: ((((!((cond1) || (cond2) || (cond3))
This is a learning exercise in expression trees. I have this working code: class
Currently, I have this method to compare two numbers Private Function ETForGreaterThan(ByVal query As
Possible Duplicate: combining two lamba expressions in c# I have two following expressions: Expression<Func<string,
I'm trying to create an expression tree dynamicly. Let asume that I have two
I have two entity classes: public class Invoice { public int ID { get;

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.