c# Entity Framework does not execute sql RRS feed

  • Question

  •  Hi,

    I have the next code:

    Guid[] sessions; while ((sessions = GetSessions()).Any()) { sessions.AsParallel().ForAll(ProcessSession); } ...

    private Guid[] GetSessions() { using (var tmpContext = new MyDbContext()) { return (from pendingSession in tmpContext.PendingSessions where !tmpContext.PendingFiles.Any(pf => pf.PendingSession.SessionId == pendingSession.SessionId) select pendingSession.SessionId).ToArray() } }

    I have traced the code running with SQLServer Profiler and recognized that the EntityFramework doesn't execute on SQLServer side the query from GetSessions method on each call of the method... I mean sometimes the sql was executed and sometimes GetSessions method is running without execution of the sql query on SQLServer side. It cause to some problems in ProcessSession method.

    What can be reason that the EntityFramwork decide to not execute the query, and what is the way to make it run each time?

    Thanks, Aleksey

    Sunday, May 12, 2013 8:15 AM

All replies