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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:44:15+00:00 2026-05-16T07:44:15+00:00

Lets say i have a form which have the following : Name:TextBox Email:TextBox Age:TextBox

  • 0

Lets say i have a form which have the following :

Name:TextBox
Email:TextBox
Age:TextBox

now i want to Get customers Collection based on this filter textboxs

so i want to to use something like :

List<customer> customers = getCustomerswhere(c=>c.name == txtName.Text && Email == txtEmail.Text);

now of course i dont know which he will fill and which he wont so

if (txtName.Text.trim() != "")
   //something like c=>c.Name == txtName.text;
if (txtEmail.Text.trim() != "")
   //something like and c=>c.Email == txtEmail.text;

how do i do this ! i cant concatenate lambda expressions , i know i can use dynamic expressions but i think there is easier way ? any idea how to implement this ?


ok i tried this:

        Func<Customer,bool > a = (bb) => bb.fullName == "asdfsd";
        Func<Customer, bool> b = c => c.lastName == "sdas";
        Func<Customer, bool> cc = c => a(c) && b(c);

now comes another problem

the method im passing CC to is expecting Expression<Func<T, bool>> expression

so it doesnt work gives me compile time error cant convert between types!

  • 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-16T07:44:16+00:00Added an answer on May 16, 2026 at 7:44 am

    Here is how i Implemented it:

       public class LambdaCriteries<T> : List<Expression<Func<T, bool>>>
    {
        public Expression<Func<T, bool>> GetFinalLambdaExpression()
        {
            var par = Expression.Parameter(typeof(T));
            var intial = Expression.Invoke(this.First(),par);
            var sec = Expression.Invoke(this.Skip(1).First(),par);
            BinaryExpression binaryExpression = Expression.And(intial, sec);
            if (this.Count> 2)
            {
                foreach (var ex in this.ToList().Skip(2))
                {
                    binaryExpression = Expression.And(binaryExpression, Expression.Invoke(ex, par));
                }
                return Expression.Lambda<Func<T, bool>>(binaryExpression,par);
            }
            else
            {
                return Expression.Lambda<Func<T, bool>>(binaryExpression,par);
            }
    
        }
    }
    

    and to use it :

               if(txtId.text != "")
                    criteries.Add(v => v.Id == int.Parse(txtId.text));
               if(txtName.text != "")
                    criteries.Add(v => v.Name == txtId.text);
    

    and final expression :

    var finalexp = criteries.GetFinalLambdaExpression();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say that you have a following simple application: <form action=helloServlet method=post> Give name:<input
Let's say I have a string in the following form: myString={name, age, address, contacts,
Lets say we have a web page with a search input form, which submits
lets say i have a main form which have a lot of functionallity. this
Let's say I have a form that collects a first name and a last
Let's say I have a form where users can search for people whose name
Let's say you have a custom form MyForm : Form and want to run
I want to do the following (c#) I have a Form,let's call Form1 Form1
I have following checkbox arrays in html form <label><input name=columns[] type=checkbox value=pname />Property Name</label>
I have the following problem. I’ve made a form which change the form elements

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.