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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:00:26+00:00 2026-05-26T01:00:26+00:00

Please see this line of code. This is an invocation of a stored procedure,

  • 0

Please see this line of code. This is an invocation of a stored procedure, which returns an ObjectResult<long?>. In order to extract the long values I added the Select:

dbContext.FindCoursesWithKeywords(keywords).Select(l => l.Value);

Based on intellisense this Select returns IEnumerable<long>.

I’m not sure whether I read it somewhere or maybe just got used to this assumption – I always thought that when the EF API returns an IEnumerable (and not IQueryable) then this means that the results have been materialized. Meaning they’ve been pulled from the database.

I found out today that I was wrong (or maybe that’s a bug?). I kept getting the error

“New transaction is not allowed because there are other threads
running in the session”

Basically, this error tells you that you’re trying to save changes while the db reader is still reading records.

Eventually I solved it by (what I considered a long shot) and added ToArray() call to materialize the IEnumerable<long>…

So – the bottom line – should I expect IEnumerable results from EF to contain results that haven’t materialized yet? If yes then is there a way to know whether an IEnumerable has been materialized or not?

Thanks and apologies if this is one of those ‘duhhh’ questions… 🙂

  • 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-26T01:00:27+00:00Added an answer on May 26, 2026 at 1:00 am

    IQueryable is used when you are using Linq-to-entities = you are building declarative LINQ query in your application which will be interpreted by LINQ provider as SQL and executed on the server. Once the query is executed (iterated) it will turn to become IEnumerable and objects will be materialized as needed for iteration = not immediately.

    Once you call stored procedure you are not using Linq-to-entities because there is no declarative query built in your application. The query / SQL already exists on database server and you are just invoking it. This will return IEnumerable but again it will not materialize all results immediately. Results will be materialized as iterated. This is principle of database cursor / or .NET data reader when you explicitly ask for fetching object.

    So if you call something like this:

    foreach (var keyword in dbContext.FindCoursesWithKeywords(keywords)
                                     .Select(l => l.Value))
    {
        ...   
    }
    

    You are fetching courses one by one (btw. why to load whole course if you are interested only in keywords?). Until you complete or break the loop your data reader is opened to fetch records.

    If you instead call this:

    foreach (var keyword in dbContext.FindCoursesWithKeywords(keywords)
                                     .ToList() // or ToArray 
                                     .Select(l => l.Value))
    {
        ...
    }
    

    You will force query to materialize all results immediately and loop will perform on collection in memory instead of opened database reader.

    Difference between IEnumerable and IQueryable is not in the way how data are fetched because IQueryable is IEnumerable. The difference is in backing construct (something must implement these interfaces).

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

Sidebar

Related Questions

Please see this piece of code: #include<stdio.h> #include<string.h> #include<stdlib.h> int main() { int i
Important : Please see this very much related question: Return multiple values in C++
Someone please see my code at this link for input taken from 2.2 mb
Hi experts please see this code: <asp:UpdatePanel ID=UpdatePanel1 runat=server UpdateMode=Conditional> <ContentTemplate> <table border=1 cellpadding=8
I see this line of code and the regular expression just panics me... quickExpr
Please see this fiddle I want the scrolling div stop following when left div
To understand what I mean, please see this snippet: <table style=width: 100%> <tbody><tr><td> <div
I'm using the Google Maps API. Please see this JSON response . The HTML
Please see the back trace below, I don´t think I have seen this before
It seems that i cannot access $(this) inside jquery ajax success function. please see

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.