<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Delayed execution vs ToList() in LINQ Database Queries</title>
	<atom:link href="http://www.ytechie.com/2009/06/delayed-execution-vs-tolist-in-linq-database-queries.html/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ytechie.com/2009/06/delayed-execution-vs-tolist-in-linq-database-queries.html</link>
	<description>Productive software development using ASP.NET, C#, Adobe Flex, and other technologies and tools.</description>
	<lastBuildDate>Wed, 01 Sep 2010 11:45:09 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Markus</title>
		<link>http://www.ytechie.com/2009/06/delayed-execution-vs-tolist-in-linq-database-queries.html/comment-page-1#comment-1531</link>
		<dc:creator>Markus</dc:creator>
		<pubDate>Thu, 02 Jul 2009 22:31:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2009/06/delayed-execution-vs-tolist-in-linq-database-queries.html#comment-1531</guid>
		<description>hmmm... I’m thinking about the following scenario:

I have a table in my database with, lets say 50 000 rows. I´m using a layered design with dal, bll and presentation.

I want to display 20 rows from the database, sorted by i.e. expireDate. I have tested there approaches:

DAL with IQueryble that returns an IQueryble of cmsDocuments:

var res = (from docs in db.cmsDocuments
                select docs);

return res;

Then binding this to a grid in the presentation.

gw.DataSource = cmsDocuments.GetAll().OrderBy(x =&gt; x.documentUser == 1).OrderBy(x=&gt;x.expireDate).Take(15);

This job gets done in around 0.04 seconds.

But using another approach would be to call the ToList() method on the res-collection in the DAL:

var res = (from docs in db.cmsDocuments
                select docs);

return res.ToList();

This will execute the query and get me all the 50 000 rows, then in my presentation (or most likey BLL) I would to the sorting:

gw.DataSource = cmsDocuments.GetAll().OrderBy(x =&gt; x.documentUser == 1).OrderBy(x =&gt; x.expireDate).Take(15);

This job gets done in around 0.35 seconds. Big difference.

My question – is the best solution to put lots of methods in the DAL, like
GetTopTeen, GetAllActive etc, and then sort dem later on?

OR is it okey to send IQuerybles to the BLL and from there make all these methods?</description>
		<content:encoded><![CDATA[<p>hmmm&#8230; I’m thinking about the following scenario:</p>
<p>I have a table in my database with, lets say 50 000 rows. I´m using a layered design with dal, bll and presentation.</p>
<p>I want to display 20 rows from the database, sorted by i.e. expireDate. I have tested there approaches:</p>
<p>DAL with IQueryble that returns an IQueryble of cmsDocuments:</p>
<p>var res = (from docs in db.cmsDocuments<br />
                select docs);</p>
<p>return res;</p>
<p>Then binding this to a grid in the presentation.</p>
<p>gw.DataSource = cmsDocuments.GetAll().OrderBy(x =&gt; x.documentUser == 1).OrderBy(x=&gt;x.expireDate).Take(15);</p>
<p>This job gets done in around 0.04 seconds.</p>
<p>But using another approach would be to call the ToList() method on the res-collection in the DAL:</p>
<p>var res = (from docs in db.cmsDocuments<br />
                select docs);</p>
<p>return res.ToList();</p>
<p>This will execute the query and get me all the 50 000 rows, then in my presentation (or most likey BLL) I would to the sorting:</p>
<p>gw.DataSource = cmsDocuments.GetAll().OrderBy(x =&gt; x.documentUser == 1).OrderBy(x =&gt; x.expireDate).Take(15);</p>
<p>This job gets done in around 0.35 seconds. Big difference.</p>
<p>My question – is the best solution to put lots of methods in the DAL, like<br />
GetTopTeen, GetAllActive etc, and then sort dem later on?</p>
<p>OR is it okey to send IQuerybles to the BLL and from there make all these methods?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.ytechie.com/2009/06/delayed-execution-vs-tolist-in-linq-database-queries.html/comment-page-1#comment-1515</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Fri, 26 Jun 2009 14:46:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2009/06/delayed-execution-vs-tolist-in-linq-database-queries.html#comment-1515</guid>
		<description>Great point logicalmind. That&#039;s concept is probably enough for its own post!</description>
		<content:encoded><![CDATA[<p>Great point logicalmind. That&#8217;s concept is probably enough for its own post!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: logicalmind</title>
		<link>http://www.ytechie.com/2009/06/delayed-execution-vs-tolist-in-linq-database-queries.html/comment-page-1#comment-1514</link>
		<dc:creator>logicalmind</dc:creator>
		<pubDate>Fri, 26 Jun 2009 14:45:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2009/06/delayed-execution-vs-tolist-in-linq-database-queries.html#comment-1514</guid>
		<description>Also note that you&#039;ve moved the exception handling responsibility when you return the IEnumberable. If there is an exception during the ToList(), such as a SQLException, the proper code layer can either handle that error properly or convert it to an exception that the calling layer can handle properly. If you return the IEnumberable then the exception is thrown during the iteration so the calling code must handle all exceptions that the iteration may throw.</description>
		<content:encoded><![CDATA[<p>Also note that you&#8217;ve moved the exception handling responsibility when you return the IEnumberable. If there is an exception during the ToList(), such as a SQLException, the proper code layer can either handle that error properly or convert it to an exception that the calling layer can handle properly. If you return the IEnumberable then the exception is thrown during the iteration so the calling code must handle all exceptions that the iteration may throw.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.ytechie.com/2009/06/delayed-execution-vs-tolist-in-linq-database-queries.html/comment-page-1#comment-1508</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Thu, 25 Jun 2009 18:02:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2009/06/delayed-execution-vs-tolist-in-linq-database-queries.html#comment-1508</guid>
		<description>Thanks Scott, that makes sense. I believe I was doing a projection into a new type, which would explain the behavior I was seeing.</description>
		<content:encoded><![CDATA[<p>Thanks Scott, that makes sense. I believe I was doing a projection into a new type, which would explain the behavior I was seeing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott Allen</title>
		<link>http://www.ytechie.com/2009/06/delayed-execution-vs-tolist-in-linq-database-queries.html/comment-page-1#comment-1507</link>
		<dc:creator>Scott Allen</dc:creator>
		<pubDate>Thu, 25 Jun 2009 17:59:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2009/06/delayed-execution-vs-tolist-in-linq-database-queries.html#comment-1507</guid>
		<description>The query does execute twice, but with Linq to SQL and the Entity Framework, you&#039;ll get the same object instances back (unless your repository is doing some sort of projection to a new type). 

Both L2S and EF use an identity map to track the objects each DataContext / ObjectContext instantiates.

See: http://odetocode.com/Blogs/scott/archive/2008/12/07/12372.aspx</description>
		<content:encoded><![CDATA[<p>The query does execute twice, but with Linq to SQL and the Entity Framework, you&#8217;ll get the same object instances back (unless your repository is doing some sort of projection to a new type). </p>
<p>Both L2S and EF use an identity map to track the objects each DataContext / ObjectContext instantiates.</p>
<p>See: <a href="http://odetocode.com/Blogs/scott/archive/2008/12/07/12372.aspx" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/odetocode.com/Blogs/scott/archive/2008/12/07/12372.aspx?referer=');">http://odetocode.com/Blogs/scott/archive/2008/12/07/12372.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arjan&#8217;s World &#187; LINKBLOG for June 24, 2009</title>
		<link>http://www.ytechie.com/2009/06/delayed-execution-vs-tolist-in-linq-database-queries.html/comment-page-1#comment-1505</link>
		<dc:creator>Arjan&#8217;s World &#187; LINKBLOG for June 24, 2009</dc:creator>
		<pubDate>Wed, 24 Jun 2009 16:30:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2009/06/delayed-execution-vs-tolist-in-linq-database-queries.html#comment-1505</guid>
		<description>[...] Delayed execution vs ToList() in LINQ Database Queries - Jason Young [...]</description>
		<content:encoded><![CDATA[<p>[...] Delayed execution vs ToList() in LINQ Database Queries &#8211; Jason Young [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
