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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:55:15+00:00 2026-05-14T03:55:15+00:00

I need to create and combine several expressions for child entity into one to

  • 0

I need to create and combine several expressions for child entity into one to use it on “Any” operator of a parent. Code now looks like this:

Expresion<Child, bool> startDateExpression;

if(String.IsNullOrEmpty(startDate)
     startDateExpression = t => true;
else
     startDateExpression = t => t.start_date >= startDate;

Expression<Child, bool> endDateExpression;

if(String.IsNullOrEmpty(endDate)
     endDateExpression = t => true;
else
     endDateExpression = t => t => t.end_date <= endDate;


....
ParameterExpression param = startDateExpression.Parameters[0];

Expression<Func<T, bool>> Combined = Expression.Lambda<Func<Child, bool>>( 
        Expression.AndAlso(startDateExpression.Body, endDateExpression.Body), param);

//but now I am trying to use combined expression on parent 
//this line fails just to give an idea on what I am trying to do:
//filter type is IQueryable<Parent>;
var filter = filter.Where(p =>p.Children.Any(Combined));

How can I do that? Is there better(more elegant way way of doing it? Maybe I should convert child expression into parent expression?

  • 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-14T03:55:15+00:00Added an answer on May 14, 2026 at 3:55 am

    I’m not entirely sure why you are building expressions instead of using lambda functions. Have you tried the following?

    var filter = filter.Where(p =>p.Children.Any(
       child => (String.IsNullOrEmpty(startDate) || child.start_date >= startDate) &&
                (String.IsNullOrEmpty(endDate) || child.end_date <= endDate)
    ));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd need to be able to combine 2 lambda expressions into 1: This would
I need to create a table that will combine two database tables together. Both
I need create custom dialog and put JPanel into it. Is it possible?
i need create a variable with parent subclass. Example: Parent Class <?php class parentClass
I use MS SQL 2008 R2, I need create a Table with a CHECK
I have dynamically created WrapPanel (_wp) with several Borders. And I need create handler
I need to create a query to combine the data from two tables, I
i need to create a transparent image, then combine transparent pngs to it whilst
I need to combine two 32-bit values to create a 64-bit value. I'm looking
I need to create a class that prevents outside code from instantiating it directly.

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.