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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:33:51+00:00 2026-05-30T13:33:51+00:00

I’m writing a custom web app (an administrative utility) that queries a SQL Server

  • 0

I’m writing a custom web app (an administrative utility) that queries a SQL Server database table, and I am giving users the ability to apply their own (limited) custom sorts and filters on the returned information. The sending page allows them to choose up to 3 sort criteria (e.g. Sort 1 then Sort 2 then Sort 3) using drop-down lists on an HTML form. They must also indicate a single letter of the alphabet (through the URL), and the application must return a list of data where field “Sort1” starts with the letter (the filtering is ALWAYS by the Sort1 field).

So for example, they could choose to return a list of all customers whose City starts with the letter “R”, sorted by City then State then Name. Or, they could return all customers whose Name starts with “F”, sorted by Name then Address then Customer ID.

I totally understand how to do this with fixed (known) fields/properties;

var _data = _data.Where(d => d.Name.StartsWith(letter)).OrderBy(p => p.Name).ThenBy(p => p.Address).ThenBy(p => p.CustomerID);

etc. But in my case, the table properties (fields) to be sorted/filtered are not explicitly known; they are only available to my app as strings. What I’d like to be able to do is…

var _data = _data.Where(d => d.["Sort1"].StartsWith(letter)).OrderBy(p => p.["Sort1"]).ThenBy(p => p.["Sort2"]).ThenBy(p => p.["Sort3"]);

where Sort1, Sort2 and Sort3 are posted form field values, but I know this doesn’t work. How can I implement this? I’m using ASP.Net MVC 3 in C#, with LINQ using the Entity Framework (EDM).

  • 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-30T13:33:52+00:00Added an answer on May 30, 2026 at 1:33 pm

    What about this approach:

    Func<Record, object> sort1 = r => GetProperty(r, "City");
    Func<Record, object> sort2 = r => GetProperty(r, "State");
    Func<Record, object> sort3 = r => GetProperty(r, "Address");
    
    Func<Record, bool> filterPredicate = p => GetProperty(p, "City").ToString().StartsWith("A");
    
    IEnumerable<Record> enumerable = list.Where(filterPredicate)
                                         .OrderBy(sort1)
                                         .ThenBy(sort2).
                                         .ThenBy(sort3);
    

    Where GetProperty is implemented as:

    static object GetProperty(Record record, string paramName)
    {
        if (paramName == "City") return record.City;
        if (paramName == "State") return record.State;
        if (paramName == "Address") return record.Address;
        if (paramName == "CustomerId") return record.CustomerId;
        throw new InvalidEnumArgumentException();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am writing an app with both english and french support. The app requests
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
I have a reasonable size flat file database of text documents mostly saved in
I'm trying to create an if statement in PHP that prevents a single post

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.