title: How to refresh context in EF6?
body: <p>I have two windows. They have separate <code>DbContext</code> objects.</p>
  
  <p>Window1 is for data view.</p>
  
  <p>Window2 is a dialog window for data editing. </p>
  
  <p>After I edit data in Window2 - I'm using <code>ctx.SaveChanges()</code> method.</p>
  
  <p>Window2 data part view:</p>
  
  <pre><code>    &lt;Button Name="SaveChanges" Click="SaveChanges_Click"&gt;Save&lt;/Button&gt;
      &lt;DataGrid Name="ListBoxLayouts"&gt; &lt;!-- "ListBox" in a name from the past --&gt;
  
  
      &lt;/DataGrid&gt;
  </code></pre>
  
  <p>Code behind: </p>
  
  <pre><code>    public Window2(ref MyContext context)
      {
          InitializeComponent();
          ctx = context;
  
          ctx.Layouts.Load();
          ListBoxLayouts.ItemsSource = ctx.Layouts.Local;
  
      }
  
  
  
      private void SaveChanges_Click(object sender, RoutedEventArgs e)
      {
  
          System.Console.WriteLine(ctx.SaveChanges());
  
          this.DialogResult = true;
          this.Close();
      }
  </code></pre>
  
  <p>When Window1 gets <code>DialogResult</code> from Window2 - I'm trying to refresh data view by disposing and creating new Window1 context</p>
  
  <pre><code>ctx.Dispose();
  ctx = new MyContext();
  
  Layouts l = context.Layouts.Where(a =&gt; a.LayoutId == 1).First();
  </code></pre>
  
  <p>and I'm getting old version of data.</p>
  
  <p><strong>What is wrong with my code?</strong></p>