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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:57:19+00:00 2026-05-17T00:57:19+00:00

How would you suggest using AsEnumerable on a non-generic IQueryable ? I cannot use

  • 0

How would you suggest using AsEnumerable on a non-generic IQueryable?

I cannot use the Cast<T> or OfType<T> methods to get an IQueryable<object> before calling AsEnumerable, since these methods have their own explicit translation by the underlying IQueryProvider and will break the query translation if I use them with a non-mapped entity (obviously object is not mapped).

Right now, I have my own extension method for this (below), but I’m wondering if there’s a way built into the framework.

public static IEnumerable AsEnumerable(this IQueryable queryable)
{
    foreach (var item in queryable)
    {
        yield return item;
    }
}

So, with the above extension method, I can now do:

IQueryable myQuery = // some query...

// this uses the built in AsEnumerable, but breaks the IQueryable's provider because object is not mapped to the underlying datasource (and cannot be)
var result = myQuery.Cast<object>().AsEnumerable().Select(x => ....);

// this works (and uses the extension method defined above), but I'm wondering if there's a way in the framework to accomplish this
var result = myQuery.AsEnumerable().Cast<object>().Select(x => ...);
  • 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-17T00:57:20+00:00Added an answer on May 17, 2026 at 12:57 am

    Since the interface IQueryable inherits from IEnumerable why not:

    IQueryable queryable;
    IEnumerable<T> = (queryable as IEnumerable).Cast<T>();
    

    Edit
    There are two Cast<> extension methods:

    public static IQueryable<TResult> Cast<TResult>(this IQueryable source)
    public static IEnumerable<TResult> Cast<TResult>(this IEnumerable source)
    

    Which one is called is statically decided by the compiler. So casting an IQueryable as an IEnumerable will cause the second extension method to be called, where it will be treated as an IEnumerable.

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

Sidebar

Related Questions

I would like to create an object of Generics Type in java. Please suggest
the buildr docs suggest using profiles.yaml for managing settings. however, i would like a
When writing a CRUD MVC application, would you suggest using arrays instead of long
I'm using Freebase suggest . If user cannot find what he is looking for,
What would you suggest as the best server stack for a dedicated server which
Which AMI would you suggest for CentOS 5.x 64-bit? There is quite a large
What algorithm would you suggest to identify how much from 0 to 1 (float)
From this post : I would first suggest that you optimize your dependentObservable (a.k.a.
As the title suggest, I would like to do the above. Example below: library(stringr)
My website's functionality would resemble with VWORKER.COM, ELANCE.COM, ODESK.COM etc. Can some one suggest

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.