I have two windows. They have separate DbContext
objects.
Window1 is for data view.
Window2 is a dialog window for data editing.
After I edit data in Window2 - I'm using ctx.SaveChanges()
method.
Window2 data part view:
<Button Name="SaveChanges" Click="SaveChanges_Click">Save</Button>
<DataGrid Name="ListBoxLayouts"> <!-- "ListBox" in a name from the past -->
</DataGrid>
Code behind:
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();
}
When Window1 gets DialogResult
from Window2 - I'm trying to refresh data view by disposing and creating new Window1 context
ctx.Dispose();
ctx = new MyContext();
Layouts l = context.Layouts.Where(a => a.LayoutId == 1).First();
and I'm getting old version of data.
What is wrong with my code?