EF making duplicate calls to databaseHey,<br/>I've got a really simple line of code that is supposed to grab all carriers in my database:<br/><br/><span style="font-size:x-small;color:#0000ff"><span style="font-size:x-small;color:#0000ff"><font size=2 color="#0000ff"><font size=2 color="#0000ff"> <p>var</p> </font></font></span><font size=2 color="#0000ff"> <p> </p> </font></span> <p><span style="font-size:x-small"> entities = db.Carrier.ToList();</span><br/><br/>For some reason, it's calling the database twice when executing this line of code, in profiler I see 2 instances of:<br/><br/>SELECT <br/>[Extent1].[CarrierId] AS [CarrierId], <br/>[Extent1].[CarrierName] AS [CarrierName], <br/>[Extent1].[EmailAddress] AS [EmailAddress], <br/>[Extent1].[CreateDate] AS [CreateDate], <br/>[Extent1].[ModifiedDate] AS [ModifiedDate]<br/>FROM [dbo].[Carrier] AS [Extent1]<br/><br/>Why is this happening and how do I get around it? I was under the impression that if you call db.Carrier, that shouldn't call the database at all until you call .ToList() on it, then it makes 1 call, but certainly not 2??<br/><br/>Even if I break it up and do this, it doesn't call the db on the first line but calls it twice on line 2 when just doing the .ToList()...<span style="font-size:x-small;color:#0000ff"><span style="font-size:x-small;color:#0000ff"><font size=2 color="#0000ff"><font size=2 color="#0000ff"> <p>var</p> </font></font></span><font size=2 color="#0000ff"> <p> </p> </font></span></p> <p><span style="font-size:x-small"> query = db.Carrier.Where(x =&gt; x.CarrierId &gt; 0);<font size=2> <p> </p> </font></span></p> <p><span style="font-size:x-small;color:#0000ff"><span style="font-size:x-small;color:#0000ff">var</span></span><span style="font-size:x-small"> entities = query.ToList();</span><br/><br/>Thanks for any help on this...</p>© 2009 Microsoft Corporation. All rights reserved.Fri, 03 Jul 2009 04:41:05 Z2403a24c-2bcf-4541-869c-ba055c276a5fhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/2403a24c-2bcf-4541-869c-ba055c276a5f#2403a24c-2bcf-4541-869c-ba055c276a5fhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/2403a24c-2bcf-4541-869c-ba055c276a5f#2403a24c-2bcf-4541-869c-ba055c276a5fboyongoohttp://social.msdn.microsoft.com/Profile/en-US/?user=boyongooEF making duplicate calls to databaseHey,<br/>I've got a really simple line of code that is supposed to grab all carriers in my database:<br/><br/><span style="font-size:x-small;color:#0000ff"><span style="font-size:x-small;color:#0000ff"><font size=2 color="#0000ff"><font size=2 color="#0000ff"> <p>var</p> </font></font></span><font size=2 color="#0000ff"> <p> </p> </font></span> <p><span style="font-size:x-small"> entities = db.Carrier.ToList();</span><br/><br/>For some reason, it's calling the database twice when executing this line of code, in profiler I see 2 instances of:<br/><br/>SELECT <br/>[Extent1].[CarrierId] AS [CarrierId], <br/>[Extent1].[CarrierName] AS [CarrierName], <br/>[Extent1].[EmailAddress] AS [EmailAddress], <br/>[Extent1].[CreateDate] AS [CreateDate], <br/>[Extent1].[ModifiedDate] AS [ModifiedDate]<br/>FROM [dbo].[Carrier] AS [Extent1]<br/><br/>Why is this happening and how do I get around it? I was under the impression that if you call db.Carrier, that shouldn't call the database at all until you call .ToList() on it, then it makes 1 call, but certainly not 2??<br/><br/>Even if I break it up and do this, it doesn't call the db on the first line but calls it twice on line 2 when just doing the .ToList()...<span style="font-size:x-small;color:#0000ff"><span style="font-size:x-small;color:#0000ff"><font size=2 color="#0000ff"><font size=2 color="#0000ff"> <p>var</p> </font></font></span><font size=2 color="#0000ff"> <p> </p> </font></span></p> <p><span style="font-size:x-small"> query = db.Carrier.Where(x =&gt; x.CarrierId &gt; 0);<font size=2> <p> </p> </font></span></p> <p><span style="font-size:x-small;color:#0000ff"><span style="font-size:x-small;color:#0000ff">var</span></span><span style="font-size:x-small"> entities = query.ToList();</span><br/><br/>Thanks for any help on this...</p>Thu, 11 Jun 2009 22:11:56 Z2009-06-11T22:11:56Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/2403a24c-2bcf-4541-869c-ba055c276a5f#c7520e88-e373-4bff-b758-5844bb1f5ef5http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/2403a24c-2bcf-4541-869c-ba055c276a5f#c7520e88-e373-4bff-b758-5844bb1f5ef5Daniel Simmons - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Daniel%20Simmons%20-%20MSFTEF making duplicate calls to databaseHow are you determining that it's calling the database twice?<br/><br/>- Danny<hr class="sig">This posting is provided &quot;AS IS&quot; with no warranties, and confers no rights.Fri, 12 Jun 2009 06:27:02 Z2009-06-12T06:27:02Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/2403a24c-2bcf-4541-869c-ba055c276a5f#f425a217-b112-4754-bd88-59bffe188874http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/2403a24c-2bcf-4541-869c-ba055c276a5f#f425a217-b112-4754-bd88-59bffe188874Daniel Simmons - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Daniel%20Simmons%20-%20MSFTEF making duplicate calls to databaseI'm going to go ahead and mark this question as answered, but if you have a follow-up question, please unmark it as answered and provide more info.<hr class="sig">This posting is provided &quot;AS IS&quot; with no warranties, and confers no rights.Fri, 03 Jul 2009 04:41:00 Z2009-07-03T04:41:00Z