title: Entity framework async issues context or query?
body: <p>I have async issue with my below query. I have singleton context and i am trying to execute below query:</p>
  
  <pre><code>var query = await (from parent in Context.ParentTable
                     join child in Context.ChildTable
                     on parent.ID equals child.ID
                     into allResult
                     from ResultValue in allResult.DefaultIfEmpty()
                     where ResultValue.TenantId == tenantId
                     select new Result
                     {
                        Code = parent.Code,
                        Type = parent.Type,
                        ID = ResultValue == null ? 0 : ResultValue.Id
                     }).ToListAsync();
  </code></pre>
  
  <p>My singleton context looks like this:</p>
  
  <pre><code>public class BaseRepository
  {
      private readonly IConfigurationContextFactory configurationContextFactory;
  
      private IConfigurationContext context;
  
      protected IConfigurationContext Context
      {
          get
          {
              return context ?? (context = configurationContextFactory.Context);
          }
      }
  
      public BaseRepository(IConfigurationContextFactory configurationContextFactory)
      {
          this.configurationContextFactory = configurationContextFactory;
      }
  }
  </code></pre>
  
  <p>The configuration context factory returns Context like this:</p>
  
  <pre><code>private ConfigurationContext Get()
  {
      logger.WriteEntrySync(LogLevel.Information,
                            null != context ? "Config Context: Using existing context." : "Config Context: Wiil create new context.");
      return context ?? (context = new ConfigurationContext(connectionString));
  }
  </code></pre>
  
  <p>In this i get intermittent issue with following error: </p>
  
  <blockquote>
    <p>A second operation started on this context before a previous
    asynchronous operation completed. Use 'await' to ensure that any
    asynchronous operations have completed before calling another method
    on this context. Any instance members are not guaranteed to be thread
    safe.</p>
  </blockquote>