0

after updating entities in a different form,I want to reload the data in the grid but it doesn't seem to update.I use:

        private void LoadData()
    {
        siparisBindingSource.DataSource = db.Siparis.Include("Kazan").ToList();
    }

To load data.After openning a dialog:

        private void değiştirToolStripMenuItem_Click(object sender, EventArgs e)
    {
        Siparis siparis = gridView1.GetFocusedRow() as Siparis;

        if (siparis != null)
        {
            FormSiparisAddEdit siparisAddEdit = new FormSiparisAddEdit {isedit = true, sipID = siparis.ID};
            siparisAddEdit.ShowDialog();
            LoadData();
        }
    }

and changing the entities,i try reloading using this method,but the contents stay the same unless i close and reopen the form.What I am i missing here?

Cheers for the answer,but i have another problem now,since i have made the db short lived,i can not get the detail data,i tried using :

        private void gridView1_MasterRowGetChildList(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowGetChildListEventArgs e)
    {
        Siparis siparis = (Siparis)gridView1.GetRow(e.RowHandle);
        using (var db = new Tank_Analizor_DBEntities())
        {
            db.Siparis.Attach(siparis);
            e.ChildList = new BindingSource(siparis, "Kazan");
        }

    }

But i get

The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.

Error,if i debug it,the child list gets the detail data...

Sin5k4
  • 1,332
  • 4
  • 29
  • 50

2 Answers2

2

Your problem is that you appear to be using a static or member data context. You should really be creating a new context each time you use it. This is how Entity Framework is designed to be used.

So change this code:

private void LoadData()
{
    using (var db = new WhateverYourContextNameIs()) {
        siparisBindingSource.DataSource = db.Siparis.Include("Kazan").ToList();
    } 
}
Erik Funkenbusch
  • 90,480
  • 27
  • 178
  • 274
  • Isn't there a way to use the connection with member data context? Because the grid I'm using (xtragrid) has internal functions that opens and closes the connection independently.. – Sin5k4 Aug 13 '13 at 20:48
0

After fiddling around a bit;I realized that since I have only one live context,I could update the selected row's object by using db.entry(object).reload();.

Sin5k4
  • 1,332
  • 4
  • 29
  • 50