Reputation: 151
I have a question about how high memory usage problems are solved in C#.
Let's say I am having a lot of item data in the database. I want to read it all then write that data to separate files and archive it to a zip file. If I get all items data from database at one time, app would timeout cause all memory is used.
What we did in our node js application we found a convenient library and used AsyncEnumerable and streamed items data in smaller pieces to a write stream.
So my question is how it is done in C#? Because I haven't found an option how data could be streamed via Entity Framework? How it is solved and could anybody give some code snippets/examples of what could be used, is it IQueryable or something else?
I'm interested in how data could be read from stream by 10000 elements at the time.
Upvotes: 0
Views: 394
Reputation: 67564
Data is streamed by default in EF, there's nothing for you to do. It's ToList()
and friends that store the entire response in memory, if you just enumerate the queryable object it'll handle any streaming in the enumerator.
Upvotes: 3