I suspect the problem is that the Entity Framework is trying to cache / track all this data in the context of your object, which ultimately leads to an OutOfMemory Exception if the data set is huge.
You can disable the shutdown manually to avoid this:
dataContext.Messages.MergeOption = System.Data.Objects.MergeOption.NoTracking;
The allocated memory that is currently located in the data context - this memory will eventually receive garbage collection after you place the context, so that you can materialize smaller batches of lines inside the used block or manually delete the object context to return memory between each batch .
source share