質問する質問する
 

回答済みEF making duplicate calls to database

  • 2009年6月11日 22:11boyongoo ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    Hey,
    I've got a really simple line of code that is supposed to grab all carriers in my database:

    var

     

    entities = db.Carrier.ToList();

    For some reason, it's calling the database twice when executing this line of code, in profiler I see 2 instances of:

    SELECT
    [Extent1].[CarrierId] AS [CarrierId],
    [Extent1].[CarrierName] AS [CarrierName],
    [Extent1].[EmailAddress] AS [EmailAddress],
    [Extent1].[CreateDate] AS [CreateDate],
    [Extent1].[ModifiedDate] AS [ModifiedDate]
    FROM [dbo].[Carrier] AS [Extent1]

    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??

    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()...

    var

     

    query = db.Carrier.Where(x => x.CarrierId > 0);

     

    var entities = query.ToList();

    Thanks for any help on this...

回答

すべての返信