Home Linq to SQL. How to read results by row and without putting all records into memory
Reply: 2

Linq to SQL. How to read results by row and without putting all records into memory

Denis Konstantinov
1#
Denis Konstantinov Published in 2018-01-12 16:24:43Z

Is it possible to read Linq to SQL result by row, without puting whole result to memory? Something like OleDB DbDataReader.Read().

Olivier Jacot-Descombes
2#
Olivier Jacot-Descombes Reply to 2018-01-12 17:14:34Z

Yes. LINQ defers its execution by default. I.e., the items are only read from the source as enumeration takes place. If you are using foreach directly (without calling .ToArray() or .ToList() first) the result set will not be stored in memory as a whole.

However, since object tracking stores information for each object being loaded, you can still get a memory overflow for very big result sets. To avoid this, set context.ObjectTrackingEnabled = false;. As a side effect, you will also notice a performance gain.

Khalil Lazhar
3#
Khalil Lazhar Reply to 2018-01-12 16:28:34Z

Yes that's the goal of Deferred execution in LinQ .Use Entity Framework and you can query using linQ and IQueryable.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.307461 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO