<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>tsJensen.com - LINQ</title>
    <link>http://www.tsjensen.com/blog/</link>
    <description />
    <language>en-us</language>
    <copyright>Tyler Jensen</copyright>
    <lastBuildDate>Wed, 07 Apr 2010 02:58:12 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.1.8139.823</generator>
    <managingEditor>tyler@tsjensen.com</managingEditor>
    <webMaster>tyler@tsjensen.com</webMaster>
    <item>
      <trackback:ping>http://www.tsjensen.com/blog/Trackback.aspx?guid=6a354e3a-58d6-441d-ad97-f375f3436cfb</trackback:ping>
      <pingback:server>http://www.tsjensen.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.tsjensen.com/blog/PermaLink,guid,6a354e3a-58d6-441d-ad97-f375f3436cfb.aspx</pingback:target>
      <dc:creator>Tyler Jensen</dc:creator>
      <wfw:comment>http://www.tsjensen.com/blog/CommentView,guid,6a354e3a-58d6-441d-ad97-f375f3436cfb.aspx</wfw:comment>
      <wfw:commentRss>http://www.tsjensen.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=6a354e3a-58d6-441d-ad97-f375f3436cfb</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I rarely just parrot-link another blogger’s post, but I’m going to make an exception
here to give props to Chris Sells and his excellent “<a href="http://www.sellsbrothers.com/news/showTopic.aspx?ixTopic=12614">The
Performance Implications of IEnumerable vs. IQueryable</a>.”
</p>
        <p>
Chris, the venerated Microsoft Legend, walks us through a great example of where the
use of IEnumerable vs IQueryable can get you into trouble. With a simple swap, Chris
goes from returning every row in a table to a simple count(*).
</p>
        <p>
The critical thing to learn is that IQueryable is “composable” meaning that you can
make one from another before executing the final “outer” query and having the composed
expression parsed and executed. 
</p>
        <p>
One additional note, however, is the gotcha that can bite you on the keester if you’re
not careful. With an IQueryable dependent upon a data context, don’t lose the context
or you’ll end up with:
</p>
        <blockquote>
          <p>
            <font color="#ff0000">
              <strong>ObjectDisposedException:</strong> Cannot access a disposed
object. Object name: 'DataContext accessed after Dispose.'.</font>
          </p>
        </blockquote>
        <p>
So watch out for the dangling context. :)
</p>
        <img width="0" height="0" src="http://www.tsjensen.com/blog/aggbug.ashx?id=6a354e3a-58d6-441d-ad97-f375f3436cfb" />
      </body>
      <title>Critical Distinction Between IEnumerable and IQueryable in LINQ to SQL or EF</title>
      <guid isPermaLink="false">http://www.tsjensen.com/blog/PermaLink,guid,6a354e3a-58d6-441d-ad97-f375f3436cfb.aspx</guid>
      <link>http://www.tsjensen.com/blog/2010/04/07/Critical+Distinction+Between+IEnumerable+And+IQueryable+In+LINQ+To+SQL+Or+EF.aspx</link>
      <pubDate>Wed, 07 Apr 2010 02:58:12 GMT</pubDate>
      <description>&lt;p&gt;
I rarely just parrot-link another blogger’s post, but I’m going to make an exception
here to give props to Chris Sells and his excellent “&lt;a href="http://www.sellsbrothers.com/news/showTopic.aspx?ixTopic=12614"&gt;The
Performance Implications of IEnumerable vs. IQueryable&lt;/a&gt;.”
&lt;/p&gt;
&lt;p&gt;
Chris, the venerated Microsoft Legend, walks us through a great example of where the
use of IEnumerable vs IQueryable can get you into trouble. With a simple swap, Chris
goes from returning every row in a table to a simple count(*).
&lt;/p&gt;
&lt;p&gt;
The critical thing to learn is that IQueryable is “composable” meaning that you can
make one from another before executing the final “outer” query and having the composed
expression parsed and executed. 
&lt;/p&gt;
&lt;p&gt;
One additional note, however, is the gotcha that can bite you on the keester if you’re
not careful. With an IQueryable dependent upon a data context, don’t lose the context
or you’ll end up with:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;font color="#ff0000"&gt;&lt;strong&gt;ObjectDisposedException:&lt;/strong&gt; Cannot access a disposed
object. Object name: 'DataContext accessed after Dispose.'.&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
So watch out for the dangling context. :)
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tsjensen.com/blog/aggbug.ashx?id=6a354e3a-58d6-441d-ad97-f375f3436cfb" /&gt;</description>
      <comments>http://www.tsjensen.com/blog/CommentView,guid,6a354e3a-58d6-441d-ad97-f375f3436cfb.aspx</comments>
      <category>Commentary</category>
      <category>LINQ</category>
    </item>
  </channel>
</rss>