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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:51:52+00:00 2026-06-10T18:51:52+00:00

If I try this, it will work: var query = myContextObject.Users.Where(u=>u.Name == John); query.ToList();

  • 0

If I try this, it will work:

var query = myContextObject.Users.Where(u=>u.Name == "John");
query.ToList();

I’m able to call ToList and a lot of other extension methods.

But if I try this:

public List ConvertQueryToList(IQueryable query)
{
    return query.ToList();
}

ToList won’t be accessible, I’m guessing this is because ToList is an extension method, but then how is that ToList is attached in the first example?
Is it possible to access ToList in the second case?

  • 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-10T18:51:53+00:00Added an answer on June 10, 2026 at 6:51 pm

    You need to write it as:

    public List<T> ConvertQueryToList<T>(IQueryable<T> query)
    {
        return query.ToList();
    }
    

    This will cause the IQueryable<T> to return the appropriate List<T>, since the Enumerable.ToList() method requires an IEnumerable<T> as input (which also works with IQueryable<T>, as IQueryable<T> inherits IEnumerable<T>).

    That being said, there is really no reason to use it this way. You can always just call ToList() directly if you need to create a List<T> – abstracting inside of a second layer just confuses the API further.

    If you’re trying to convert a non-generic IQueryable interface, you would need to do something like:

    public List<T> ConvertQueryToList<T>(IQueryable query)
    {
        return query.Cast<T>.ToList();
    }
    

    This would then require calling like:

    var results = ConvertQueryToList<SomeType>(queryable);
    

    Alternatively, if you want to leave this non-generic (which I wouldn’t recommend), then you could use:

    public ArrayList ConvertQueryToList(IQueryable query)
    {
        ArrayList results = new ArrayList();
        results.AddRange(query.Cast<object>().ToList());
        return results;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This will probably be a bot of a waffly question but ill try my
I try to write a Facebook app. This app will communicate with a rfid
I will try and word this question the best I can, for it is
I will try to make this as clear as I can, but if you
I will try to keep this as simple as possible. I have a rather
I know i will get this exception when i try to modify or remove
I'm going to try to explain this best I can I will provide more
This is kind of a oddball problem so I will try to describe the
this is so that I will have to build a delete function, I try
sorry for asking this dumb question i will try to explain as good as

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.