질문하기질문하기
 

답변됨EF making duplicate calls to database

  • 2009년 6월 11일 목요일 오후 10: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...

답변

모든 응답