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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:18:07+00:00 2026-05-20T23:18:07+00:00

I have started using the entity framework for a web application and would like

  • 0

I have started using the entity framework for a web application and would like to know what the best way would be to allow users to filter lists dynamically.
i.e. If we have a list of people the user can filter by lastname, city, etc.

The problem I am having is that I am using EF 4 with code first and all the fitlering I can find is using Linq queries but I can’t see a way to build up the where clause for the filter dymaically based on the filter options the user has selected. i.e. in SQL you could build,

select * from people, address where lastname = 'jones' and address.city = 'sydney'

Is there a way to build up this list dynamically using linq?

EDIT
The solution I’m going to try will be similar to this Implementing Dynamic Searching Using LINQ. As I prefer to be as generic as possible where I can.

  • 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-20T23:18:08+00:00Added an answer on May 20, 2026 at 11:18 pm

    The way to do this is for example defining some type for search criteria:

    public class PeopleSearchCriteria
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string City { get; set; }
    }
    

    and define custom extension method for IQueryable<Person> :

    public static IQueryable<Person> FilterBySearchCriteria(this IQueryable<Person> query, 
         PeoplseSearchCritera criteria)
    {
        if (!String.IsNullOrEmpty(criteria.FirstName))
        {
            string firstName = criteria.FirstName;
            query = query.Where(p => p.FirstName == firstName);
        }
    
        // do similar code for other criterias
    
        return query;
    }
    

    Now you only need to create model binder (or use default one if possible) to fill your serach options to PeopleSearchCriteria instance and execute simply:

    var data = context.People.FilterBySearchCriteria(searchCriteria).ToList();
    

    If you really want some dynamic approach you can build expression tree manually or check Dynamic Linq (you will lose compile time checks).

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

Sidebar

Related Questions

I am using Entity Framework with my website. To improve performance, I have started
I have started using custom intents in my application and I have come across
I'm using entity framework and i have a problem that this dropdown ignores my
I have started to look at the Entity Framework for a project I am
I'm writing a standalone application and I thought using Entity Framework to store my
I've recently started using Entity Framework migrations and noticed that the database name is
I am getting started with Entity Framework using POCO in a model-first configuration. I
I have recently started to learn using of Doctrine 2.0 framework for PHP. Now
I started using Entity Framework (Using POCO Classes) for a MVC 3 C# project
I recently started using Entity Framework, and it has been kind of a pain

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.