<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Migrating from LINQ to SQL to Entity Framework: Deferred Loading</title><link>http://blogs.msdn.com/adonet/archive/2008/10/16/migrating-from-linq-to-sql-to-entity-framework-deferred-loading.aspx</link><description>Last week, we covered Eager Loading and how to migrate LINQ to SQL based code that took advantage of Eager Loading. This week, we discuss Deferred Loading. Generally speaking, queries only retrieve the objects you request, and not their related objects.</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Migrating from LINQ to SQL to Entity Framework: Deferred Loading</title><link>http://blogs.msdn.com/adonet/archive/2008/10/16/migrating-from-linq-to-sql-to-entity-framework-deferred-loading.aspx#9002480</link><pubDate>Fri, 17 Oct 2008 01:41:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9002480</guid><dc:creator>Stephen redd</dc:creator><description>&lt;p&gt;The lack of automatic deferred loading is a deal-breaker. &lt;/p&gt;
&lt;p&gt;I respect the &amp;quot;reasons&amp;quot; for not having it enabled by default, and I understand why many might choose not to use it.&lt;/p&gt;
&lt;p&gt;The lack of automatic lazy loading means that EF produces entities that you just CANNOT trust. I don't know about anyone else, but when I get a reference to an object, I EXPECT that when I call one of its properties that the property will not blow up in my face! I EXPECT the property to contain data, and that the data will be valid and accurate. &lt;/p&gt;
&lt;p&gt;In EF though, when I call the SalesOrderDetail property I have no way to &amp;quot;know&amp;quot; what I'm going to get back. I might get back nothing... but am I getting nothing because it isn't loaded or because there just wasn't any data in the data store? I might get back an error, but it depends on the kind of property... not that getting an error makes me happy either. &lt;/p&gt;
&lt;p&gt;Sure, I can explicitly check to see if data is loaded or not, but the mechanism to perform this check requires that I know a lot about the internals of the entity and the relationships between them. For example, I have to know if the property is a navigation property or not in order to know if I should check loaded. &amp;nbsp;Also, the mechanism to do the IsLoaded check is awkward.&lt;/p&gt;
&lt;p&gt;Also, if &amp;nbsp;you pass the entity to another class as a return value... now you might not have the ability to explicitly load the related data at all (no context)... but the entity will still contain the booby-trapped properties. &lt;/p&gt;
&lt;p&gt;Then there is the sheer noise of all those checks for loaded data and loads. Even in rather trivial applications I end up with more code just to do checks and loads than I have code to actually use the data. &lt;/p&gt;
&lt;p&gt;The weight of all this is massive.&lt;/p&gt;
&lt;p&gt;Look guys, the whole point of using something like EF and LINQ to Entities is to make data access simpler and better... &lt;/p&gt;
&lt;p&gt;I shouldn't have to be suspicious and paranoid of each and every call to an entity. I shouldn't have to baby-sit the API constantly asking &amp;quot;are you sure&amp;quot; before I call a property. And I shouldn't have to know THAT much about the inner workings and relationships inside my logical model just to be able to use the entity without having my code blowing up in my face. &lt;/p&gt;
&lt;p&gt;The whole point of EF was to gain abstraction... not force me to know the logical model inside-and-out.&lt;/p&gt;
&lt;p&gt;Sure... I might WANT explicit deferred loading, but I shouldn't be FORCED to it ALL of the time. &lt;/p&gt;
</description></item><item><title>re: Migrating from LINQ to SQL to Entity Framework: Deferred Loading</title><link>http://blogs.msdn.com/adonet/archive/2008/10/16/migrating-from-linq-to-sql-to-entity-framework-deferred-loading.aspx#9006806</link><pubDate>Mon, 20 Oct 2008 06:27:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9006806</guid><dc:creator>Gregory Kornblum</dc:creator><description>&lt;p&gt;Very good argument Stephen. You should write an article about this instead of a comment to someone else's.&lt;/p&gt;
</description></item><item><title>re: Migrating from LINQ to SQL to Entity Framework: Deferred Loading</title><link>http://blogs.msdn.com/adonet/archive/2008/10/16/migrating-from-linq-to-sql-to-entity-framework-deferred-loading.aspx#9010507</link><pubDate>Wed, 22 Oct 2008 02:20:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9010507</guid><dc:creator>Stephen Redd</dc:creator><description>&lt;p&gt;Thanks Gregory,&lt;/p&gt;
&lt;p&gt;I did write an article about it on my personal site back when I was still angry over the whole thing, but I was a little harsher in that article (strong language warning): &lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://reddnet.net/code/ado-net-entity-framework-impressive-powerful-useless/"&gt;http://reddnet.net/code/ado-net-entity-framework-impressive-powerful-useless/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I do make a point to express the same concerns whenever I see the topic come up and it seems like it might be relevant to the discussion.&lt;/p&gt;
&lt;p&gt;I might complain loudly, but I am confident that the data team at Microsoft is hearing this same message, and I am confident that they will fix this issue up in the next major release.&lt;/p&gt;
&lt;p&gt;But just in case, I keep complaining :P&lt;/p&gt;
</description></item><item><title>And the winner is… LINQ to Entities and the ADO.NET Entity Framework</title><link>http://blogs.msdn.com/adonet/archive/2008/10/16/migrating-from-linq-to-sql-to-entity-framework-deferred-loading.aspx#9033871</link><pubDate>Mon, 03 Nov 2008 19:55:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9033871</guid><dc:creator>Eric and the .NET Framework</dc:creator><description>&lt;p&gt;In 2001 we first demonstrated Object Relational Mapping (ORM) technology for .NET – ObjectSpaces . However&lt;/p&gt;
</description></item><item><title>re: Migrating from LINQ to SQL to Entity Framework: Deferred Loading</title><link>http://blogs.msdn.com/adonet/archive/2008/10/16/migrating-from-linq-to-sql-to-entity-framework-deferred-loading.aspx#9283836</link><pubDate>Tue, 06 Jan 2009 01:35:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9283836</guid><dc:creator>Allen</dc:creator><description>&lt;p&gt;There is no way we'll use this if we have to check everything to see if a property is loaded or not. &amp;nbsp;The team better make some changes to that or this thing is DOA. &amp;nbsp;I can't believe they would make such a huge mistake.&lt;/p&gt;
</description></item><item><title>re: Migrating from LINQ to SQL to Entity Framework: Deferred Loading</title><link>http://blogs.msdn.com/adonet/archive/2008/10/16/migrating-from-linq-to-sql-to-entity-framework-deferred-loading.aspx#9303329</link><pubDate>Sat, 10 Jan 2009 06:20:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9303329</guid><dc:creator>Simon Segal</dc:creator><description>&lt;p&gt;I believe eager and lazy loading should and need to be possible by developers expressing their intent prior to accessing attributes of objects. I want and need to have Fetching Strategies as per the NHibernate implementation. Using fetching strategies I have the option of injecting them and easily distributing and re-distributing them. I demonstrated this with LINQ to SQL here : &lt;a rel="nofollow" target="_new" href="http://www.simonsegal.net/blog/2008/09/16/linq-to-sql-going-poco-and-more/"&gt;http://www.simonsegal.net/blog/2008/09/16/linq-to-sql-going-poco-and-more/&lt;/a&gt; and you could do the same by wrapping the .Includes extension method however it doesn't correlate well with lazy loading which causes a friction in developing a satisfying outcome. I would prefer my code not to be tightly coupled to my fetching requirements over time immemorial as they are by sprinking them explicitly throughout using .Includes() and .IsLoaded(). &lt;/p&gt;
</description></item><item><title>re: Migrating from LINQ to SQL to Entity Framework: Deferred Loading</title><link>http://blogs.msdn.com/adonet/archive/2008/10/16/migrating-from-linq-to-sql-to-entity-framework-deferred-loading.aspx#9321540</link><pubDate>Thu, 15 Jan 2009 23:50:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9321540</guid><dc:creator>TT</dc:creator><description>&lt;p&gt;The main reason for disabling lazy loading is the risk of loosing control over when and how you hit the database.&lt;/p&gt;
&lt;p&gt;Inexperienced developers are protected against making database call in an unwanted manner. So why is it that more Linq2Sql developers don't have more problems with lazy loading even though they statistically would be more inexperienced users? &lt;/p&gt;
&lt;p&gt;I think it is because if you if you do the error of calling Linq to .... code unaware of what physical storage that lies behind you would get into performance problems very soon and people learn quickly how to avoid this. You cannot be ignorant of what is being called behind the scenes when doing linq queries. That is one of the many reasons I like Linq2Sql over Entity Framework and even NHibernate since it clearly displays the database scheme you are querying. The database is usually the biggest performance factor in a normal web app so every developer should know the database they are querying.&lt;/p&gt;
</description></item><item><title>re: Migrating from LINQ to SQL to Entity Framework: Deferred Loading</title><link>http://blogs.msdn.com/adonet/archive/2008/10/16/migrating-from-linq-to-sql-to-entity-framework-deferred-loading.aspx#9459308</link><pubDate>Thu, 05 Mar 2009 07:51:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9459308</guid><dc:creator>Ken Smith</dc:creator><description>&lt;p&gt;An even bigger problem with not having Lazy Loading implemented is that there are times you can call the &amp;quot;.Include()&amp;quot; method in your LINQ, and then by the time LINQ gets around to generating your result, it forgets that you've asked it to include the related objects. &amp;nbsp;For instance, if you use the new {} syntax at the end of your query, none of the navigations that you've asked in the middle of your query are remembered. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;See here for instance:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=347543"&gt;https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=347543&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;///&amp;lt;Not working!&amp;gt;&lt;/p&gt;
&lt;p&gt;var q2 = from p in ent.Products.Include(&amp;quot;Categories&amp;quot;)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;where p.ProductID == 1&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;select new&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Product = p,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SupplierCity = p.Suppliers.City&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;};&lt;/p&gt;
&lt;p&gt;var prod2 = q2.First();&lt;/p&gt;
&lt;p&gt;//comment: no eager loading -&amp;gt; prod2.Product.CategoriesReferense.IsLoaded == false&lt;/p&gt;
&lt;p&gt;///&amp;lt;/Not working!&amp;gt;&lt;/p&gt;
&lt;p&gt;Whatever else this does, it certainly violates the principle of least astonishment. &amp;nbsp;It also creates headaches in a number of places, for instance, if you're trying to bind to the results of a query in WPF, and don't have the luxury of checking .IsLoaded() before accessing an object's navigation properties. &amp;nbsp;This definitely needs to get fixed.&lt;/p&gt;
</description></item><item><title>re: Migrating from LINQ to SQL to Entity Framework: Deferred Loading</title><link>http://blogs.msdn.com/adonet/archive/2008/10/16/migrating-from-linq-to-sql-to-entity-framework-deferred-loading.aspx#9635035</link><pubDate>Fri, 22 May 2009 14:01:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9635035</guid><dc:creator>Medyum</dc:creator><description>&lt;p&gt;There is no way we'll use this if we have to check everything to see if a property is loaded or not. &amp;nbsp;The team better make some changes to that or this thing is DOA. &amp;nbsp;I can't believe they would make such a huge mistake.&lt;/p&gt;
</description></item><item><title>re: Migrating from LINQ to SQL to Entity Framework: Deferred Loading</title><link>http://blogs.msdn.com/adonet/archive/2008/10/16/migrating-from-linq-to-sql-to-entity-framework-deferred-loading.aspx#9822665</link><pubDate>Tue, 07 Jul 2009 17:41:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9822665</guid><dc:creator>hikaye</dc:creator><description>&lt;p&gt;There is no way we'll use this if we have to check everything to see if a property is loaded or not. &amp;nbsp;The team better make some changes to that or this thing is DOA. &amp;nbsp;I can't believe they would make such a huge mistake.&lt;/p&gt;
</description></item><item><title>re: Migrating from LINQ to SQL to Entity Framework: Deferred Loading</title><link>http://blogs.msdn.com/adonet/archive/2008/10/16/migrating-from-linq-to-sql-to-entity-framework-deferred-loading.aspx#9846405</link><pubDate>Thu, 23 Jul 2009 17:42:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9846405</guid><dc:creator>ssk sorgulama</dc:creator><description>&lt;p&gt; &amp;nbsp; &amp;nbsp;The main reason for disabling lazy loading is the risk of loosing control over when and how you hit the database.&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Inexperienced developers are protected against making database call in an unwanted manner. So why is it that more Linq2Sql developers don't have more problems with lazy loading even though they statistically would be more inexperienced users?&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;I think it is because if you if you do the error of calling Linq to .... code unaware of what physical storage that lies behind you would get into performance problems very soon and people learn quickly how to avoid this. You cannot be ignorant of what is being called behind the scenes when doing linq queries. That is one of the many reasons I like Linq2Sql over Entity Framework and even NHibernate since it clearly displays the database scheme you are querying. The database is usually the biggest performance factor in a normal web app so every developer should know the database they are querying.&lt;/p&gt;
</description></item><item><title>re: Migrating from LINQ to SQL to Entity Framework: Deferred Loading</title><link>http://blogs.msdn.com/adonet/archive/2008/10/16/migrating-from-linq-to-sql-to-entity-framework-deferred-loading.aspx#9846584</link><pubDate>Thu, 23 Jul 2009 19:55:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9846584</guid><dc:creator>zerrin egeliler</dc:creator><description>&lt;p&gt;a very good article da a very useful information ..thank you has to share this information.&lt;/p&gt;
</description></item></channel></rss>