Try explicitly enumerating the results by calling ToList()
.
Change
foreach (var item in query)
to
foreach (var item in query.ToList())
More Related Contents:
- Entity Framework Timeouts
- Entity Framework/Linq EXpression converting from string to int
- LEFT JOIN in LINQ to entities?
- “The LINQ expression node type ‘Invoke’ is not supported in LINQ to Entities” – stumped!
- Creating dynamic queries with entity framework
- One DbContext per web request… why?
- There is already an open DataReader associated with this Command which must be closed first
- Validation failed for one or more entities. See ‘EntityValidationErrors’ property for more details [duplicate]
- ‘Contains()’ workaround using Linq to Entities?
- How to use a string to create a EF order by expression?
- The mapping of CLR type to EDM type is ambiguous with EF 6 & 5?
- Does Entity Framework 4 Code First have support for identity generators like NHibernate?
- Dynamic MySQL database connection for Entity Framework 6
- Entity Framework 6 Code First Custom Functions
- LINQ to Entities does not recognize the method ‘System.Web.Mvc.FileResult’
- Order by dynamic parameter
- Dynamic table name in linq [duplicate]
- Why is Asp.Net Identity IdentityDbContext a Black-Box?
- Find all child controls of specific type using Enumerable.OfType() or LINQ
- Join and Include in Entity Framework
- Setting the default value of a DateTime Property to DateTime.Now inside the System.ComponentModel Default Value Attrbute
- Log Queries executed by Entity Framework DbContext
- The data source does not support server-side data paging
- Remove item from list based on condition
- “Context cannot be used while the model is being created” exception with ASP.NET Identity
- How to group by DateTime.Date in EntityFramework
- Linq Query keeps throwing “Unable to create a constant value of type System.Object….”, Why?
- How to include() nested child entity in linq
- LINQ Query to Convert string to datetime
- Entity Framework select one of each group by date