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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:25:37+00:00 2026-06-06T17:25:37+00:00

I have a database with several hundred tables imported from a third source. Using

  • 0

I have a database with several hundred tables imported from a third source. Using entity framework, these tables become ObjectSets labeled E_1, E_2, E_3… All of the tables have a common set of columns and can be queried with one function.

I have the following code:

namespace Foo{
    public static class Data{

       public static MyEntities dataContext = new MyEntities();

       public static void getData<T>(string entityName) where T : class
       {
          string queryString = "SELECT result FROM ";
          queryString += Data.dataContext.DefaultContainerName + "." + entityName;

          ObjectQuery<T> myQuery = Data.dataContext.CreateQuery<T>(queryString, null);

        // do stuff
       }

       public static void test(){
         string entityName = "E_1";
         Data.getData<E_1>(entityName);
       }
}

In test(), I pass the string “E_1” to the function getData(), and I also insert type class Foo.E_1 into getData<> as the generic type parameter.

In reality, E_1 isn’t known until run time. At run time, I create the entityName string, but how can I then convert this string into the generic parameter type needed for getData<>?

Thanks.

  • 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-06T17:25:39+00:00Added an answer on June 6, 2026 at 5:25 pm

    All of the tables have a common set of columns

    So you can make one class (e.g. MyImportType) to capture the results of your query, and use ExecuteStoreQuery in stead of ObjectQuery

    var data = Data.dataContext.ExecuteStoreQuery<MyImportType>(queryString);
    

    And getData does not need a generic type parameter.

    As aside: I agree with TomTom that the db design is very bad. If you can, at least merge the tables with identical columns into one table.

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

Sidebar

Related Questions

I have a SQL database that has several hundred tables in it, but I
I have several database tables that just contain a single column and very few
I have an Access database (in Access 2003) with several tables, and data must
I have a MySQL database that I am keeping temperature readings from several different
I have several database tables that have data that is for display purposes only,
I have a SQL Server 2000 database with around a couple of hundred tables.
I have a database table. It has several hundred entries and each entry is
I have an SQLite database that stores several hundred or thousand strings, I keep
I am going to have a database with several (less than 10) main tables.
I want to import several .sql files into database using source command (mysql command

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.