Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>LINQ has many incarnations. Since you mention LINQ-to-SQL, I'll focus on that: it is neither... it is most comparable to <code>IDataReader</code> - i.e. it executes a constructed TSQL command, and then returns the processed records row-by-row (see below) as it receives them from the SQL Server. As with <code>IDataReader</code>, you only get one chance per row, unless you buffer the data using <code>.ToArray()</code>, <code>.ToList()</code>, etc.</p> <p>The TSQL command executed is constructed from the LINQ query you build, and is parameterized to prevent SQL injection - so if you use "where", the TSQL executed includes "WHERE", etc.</p> <p>In reality, the client is consuming records on demand via <code>IEnumerable[&lt;T&gt;]</code>, so there needs to be a small buffer to handle the incoming TDS stream - but it isn't the same as a database cursor.</p> <p>Note that most operations (Sort, etc) can be sent down to the server and translated into TSQL - but it is possible that some things have to be done at the client, which might again force it to buffer more data in memory. This is especially true if you force it via <code>.ToEnumerable()</code>, which switches to LINQ-to-Objects. If LINQ-to-Objects does a buffering operation (sort, group, etc), then it will need to load the data into memory.</p> <p>There are a few things of note here; for example, if you want to compute completely separate aggregates etc on a query, you must (normally) either execute it twice (etc), or buffer it all in memory (not necessarily an option for large data). For this type of scenario (and others), Jon Skeet and myself wrote an alternative LINQ implementation that works as a <em>push</em> rather than a <em>pull</em>, allowing you to feed data through multiple parallel processes at once. Jon explains it better <a href="http://codeblog.jonskeet.uk/2008/01/04/quot-push-quot-linq-revisited-next-attempt-at-an-explanation/" rel="nofollow noreferrer">here</a>. This type of thing is mainly of use if you have a very large, once-only data stream that you want to do complex processing on. Interesting, though.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload