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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:03:04+00:00 2026-06-13T07:03:04+00:00

I have a Dictionary: Dictionary<int, Type> AllDrillTypes = new Dictionary<int, Type>() { {13,typeof(TCHEMISTRY)}, {14,typeof(TDRILLSPAN)}

  • 0

I have a Dictionary:

Dictionary<int, Type> AllDrillTypes = new Dictionary<int, Type>()
{
  {13,typeof(TCHEMISTRY)},
  {14,typeof(TDRILLSPAN)}
};

where TCHEMISTRY and TDRILLSPAN are classes. Then I want to get rows from one of this classes like this:

Type T = AllDrillTypes[13];
var LC = Activator.CreateInstance( typeof(List<>).MakeGenericType( T ) );
MethodInfo M = T.GetMethod("FindAll", BindingFlags.Public | BindingFlags.Static, null, new Type[] { }, null);    
LC = M.Invoke(null, new object[] { });

All this code works correctly. After that I need to get some rows like this:

var LingLC = from obj in LC where obj.RunID == 1001 select obj;

But this line causes error:

“Could not find an implementation of the query pattern for source type
‘object’. ‘Where’ not found.”

What’s wrong with this code line?

  • 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-13T07:03:06+00:00Added an answer on June 13, 2026 at 7:03 am

    Even if you can’t change the class definitions, you can avoid using reflection:

    // Getter dictionary rather than type dictionary.
    Dictionary<int, Func<IEnumerable<object>>> DrillTypeGetters =
        new Dictionary<int, Func<IEnumerable<object>>>()   
        {  
            { 13, () => TCHEMISTRY.FindAll().Cast<object>() },
            { 14, () => TDRILLSPAN.FindAll().Cast<object>() }
        };
    Dictionary<int, Func<object, int>> IDGetters =
        new Dictionary<int, Func<object, int>>()
        {
            { 13, o => ((TCHEMISTRY)o).RunID },
            { 14, o => ((TDRILLSPAN)o).RunID }
        };
    
    IEnumerable<object> LC = DrillTypeGetters[13]();
    IEnumerable<object> LingLC = 
        from obj in LC
        where IDGetters[13](obj) == 1001
        select obj;
    

    Or you could even just switch on 13/14 and run a completely different method per type.

    if (choice == 13)
        IEnumerable<TCHEMISTRY> LingLC =
            TCHEMISTRY.FindAll().Where(tc => tc.RunID == 1001);
    else if (choice == 14)
        IEnumerable<TDRILLSPAN> LingLC =
            TDRILLSPAN.FindAll().Where(td => td.RunID == 1001);
    

    Basically, if the two classes don’t share any common hierarchy, you can’t write any common code to deal with them. If they have lots of similar properties, you can use getters as in my first example to provide a way to get the similar properties whatever type of class you’re dealing with. If they don’t even have similar properties, don’t try to write shared code.

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

Sidebar

Related Questions

I have a dictionary of type Dictionary<Guid,int> I want to return the first instance
I have a dictionary of type Dictionary<int, double> and want to eliminate values equal
I have a Dictionary<int, string> which I want to take the Key collection into
I have Two Dictionary DictA & DictB such as: Dictionary<int, string> DictA = new
I have dictionary, like Dictionary<string, bool> accValues = new Dictionary<string, bool>() And I want
I have used AutoCompleteBox usercontrol. I have a dictionary of type Dictionary<int,string> which contains
I have a Dictionary<int, int> idsAndTypes = new Dictionary<int, int>(); and i have a
I have a dictionary declared like this. public static Dictionary<int?, List<int?>> pegMap = new
I have MVC 3 application and I have dictionary of type Dictionary<String,int> in c#.
I have a dictionary like the follow: public Dictionary<int, SpawnList> spawnEntities = new Dictionary<int,

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.