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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:39:41+00:00 2026-05-29T09:39:41+00:00

I have user-interface where user can select grid column (like age) and operator (lesser

  • 0

I have user-interface where user can select grid column (like age) and operator (lesser than, equals or greater than) for that column.

Grid data is then filtered according to the selection.

I have a following classes that are deserialized from the JSON that is coming from the client.

/// <summary>
/// Filter for reducing grid results
/// </summary>
public class Filter
{
    /// <summary>
    /// Name of the column
    /// </summary>
    public string name;

    public string value;

    public int @operator { private get; set; }

    public Operator Operator()
    {
        return (Operator) @operator;
    }
}

public enum Operator
{
    None = -1,
    LesserThan = 0,
    Equals = 1,
    GreaterThan = 2
}

Due to the nature dynamically adding new columns for filtering I would like to create generic solution for accessing the data.

I would like avoid having huge amount if/switch statements like

switch(columnName)
{
    case "age":
    {
        if(operator == Operator.LesserThan)
        {
             query = entities.Where(o => o.Age < age);
        }
        else if (operator == Operator.GreaterThan)
        {
             query = entities.Where(o => o.Age > age);
        }
        etc.

        break;
    }
    etc.
}

Any ideas how to create more generic solution for the problem?

Update
It seems that there many ways to accomplish cleaner solution than one billion if statements. Now I just need to compare different solutions.

  • 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-29T09:39:42+00:00Added an answer on May 29, 2026 at 9:39 am

    You could use Dynamic LINQ to create the query dynamically

    Edit:

    An example for Dynamic LINQ query would look like this, assuming that the column names in the grid are the same as the field names in the entity:

    string queryString;
    queryString = columnName;
    if(operator == Operator.LesserThan)
    {
      queryString += " < ";
    }
    else if (operator == Operator.GreaterThan)
    {
      queryString += " > ";
    }
    etc.
    queryString += age.ToString();  // Or use bind variables, haven't tried that myself in dynamic LINQ
    
    query = entites.Where(queryString);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume I have a user interface where the user can select days. Is there
I have a fairly large application that uses WPF for its user interface. I
I have written an application (using Delphi 2009) that allows a user to select
I have a web app where a user can assemble a user interface (such
I'd ideally like to create a streamlined interface which requires the user to select
I have a User Interface where users can type in first name and last
A lot of JavaScript libraries have user interface widgets. Usually they are created after
I have a user interface in .net which needs to receive data from a
Applications which run on mobile devices have special user interface requirements. I think Apple
I have to make a graphical user interface application using the language of my

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.