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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:04:51+00:00 2026-06-17T11:04:51+00:00

I am trying to use a string to determine the table that I am

  • 0

I am trying to use a string to determine the table that I am performing my query on. However I can not find any way to do this. Here is my code:

ADVENTUREWORKSSUPEREntities context = new ADVENTUREWORKSSUPEREntities();
string table = "Addresses" //this is set elsewhere in the code but I put it here for clarity

            if (table == "Addresses")
            {
                results.ItemsSource = context.Addresses.Where(condition).ToList();
            }
            else if (table == "Customers")
            {
               results.ItemsSource = context.Customers.Where(condition).ToList();
            }
              ...
              ...
              ...
            else if (table == "SalesOrderHeaders")
            {
                results.ItemsSource = context.SalesOrderHeaders.Where(condition).ToList();
            }

Is it possible to replace the

results.ItemsSource = context.Addresses.Where(condition).ToList();

with a line that uses my table string instead of Addresses?
Thus it would be

results.ItemsSource = context.[table].Where(condition).ToList();

Edit:

I’m doing this as an exercise to learn wpf/entity framework/C#. As I am watching videos on puralsight I am thinking of stuff to try and adding it to this program.

  • 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-06-17T11:04:52+00:00Added an answer on June 17, 2026 at 11:04 am

    Here is the solution that I came up with.

    dynamic test = t.InvokeMember(table,
                            BindingFlags.DeclaredOnly |
                            BindingFlags.Public | BindingFlags.NonPublic |
                            BindingFlags.Instance | BindingFlags.GetProperty, null, context, new object[0]);
    
                ((IQueryable)test).AsQueryable().Where(condition).Load();
                results.ItemsSource = test.Local;
    

    Thanks to everyone that commented/answered for all the help and pointing me in good directions.

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

Sidebar

Related Questions

Im trying to use the string::find method to determine if the string hello (with
I'm trying to determine a way to find all words in a database table
I'm trying to use regex to match a string that starts with a <p>
I am trying to determine the best way to save an unknown string on
I'm trying to use a stored procedure to create a table that ranks posts
I am trying to use Jackson JSON take a string and determine if it
I'm trying to find a way to determine how many parameters a constructor has.
I'm trying to use Rubygame to determine each of a string's character widths as
I'm trying to use a string value of say, [ScheduledDate] < '11/1/2011', and test
I am trying to use a string to call a method? Suppose I have

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.