07-20-2023, 11:22 AM
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... :)
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... :)