title: SqlDependency with EntityFramework 6 (async)
body: <p>I'm using the EF 6 <code>async</code> querying features, such as</p>
  
  <pre><code>var list = await cx.Clients.Where(c =&gt; c.FirstName.Length &gt; 0).ToListAsync();
  </code></pre>
  
  <p>I want to also start SQL dependencies on these queries so that I can get notified when the data in the database changes. I can do this using the <code>System.Runtime.Remoting.Messaging.CallContext</code> as follows:</p>
  
  <pre><code>    async Task GetData()
      {
          using (ClientsContext context = new ClientsContext()) // subclass of DbContext
          {
  
              SqlDependency.Start(context.Database.Connection.ConnectionString);
              SqlDependency dependency = new SqlDependency();
              dependency.OnChange += (sender, e) =&gt;
                  {
                      Console.Write(e.ToString()); 
                  };
  
              System.Runtime.Remoting.Messaging.CallContext.SetData("MS.SqlDependencyCookie", dependency.Id);
              var list = await context.Clients.Where(c =&gt; c.FirstName.Length &gt; 0).ToListAsync();
          }
      }
  </code></pre>
  
  <p>.. and it works fine. But I am running into an issue if I want to have an <code>SqlDependency</code> on more than one query. If I have two <code>async</code> methods similar to <code>GetData()</code> above, and I run both at the same time, only the first one will get change notifications. I assume that this is due to the CallContext having the cookie set by each method in succession. If I wait for the first <code>async</code> method to complete, then call the second, they both get change notifications as expected. Is there any solution to this?</p>