Disconnected model: error updating childobject in DB
Posted: Tue 03 Mar 2009 15:20
Hi Forum,
Please help me out: maybe i'm making a mistake or maybe i found an error.
I have two tables: tblParent (walnumber) and tblChild (employee)
tblChild has a foreign key relationship to tblParent.
When i try to update the tblChild the following way:
I get the following error:
So it seems that the datacontext cannot update a child relaction to the database when the parent table that is referenced is not loaded into the datacontext.
Is that by design or am i doing something wrong ?
Please help me out: maybe i'm making a mistake or maybe i found an error.
I have two tables: tblParent (walnumber) and tblChild (employee)
tblChild has a foreign key relationship to tblParent.
When i try to update the tblChild the following way:
Code: Select all
Employee employee = Employee.GetSingleByPrimaryKey(grid_employees.SelectedDataKey.Value.ToString());
using (umbrellaDataContext.umbrellaDataContext db = new umbrellaDataContext.umbrellaDataContext())
{
db.Employees.Attach(employee);
employee.Betweenfix = txt_e_infix.Text;
employee.Email = txt_e_email.Text;
employee.Faxnumber = txt_e_fax.Text;
employee.Firstname = txt_e_firstname.Text;
employee.Lastname = txt_e_lastname.Text;
employee.Telephone_Celluar = txt_e_celluar.Text;
employee.Telephone_Office = txt_e_officenumber.Text;
employee.Title = txt_e_title.Text;
db.SubmitChanges();
}
Code: Select all
Cannot access a disposed object.
Object name: 'DataContext accessed after Dispose.'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'DataContext accessed after Dispose.'.
Source Error:
Line 6524: get
Line 6525: {
Line 6526: return this._Walnumber.Entity;
Line 6527: }
Line 6528: set
Is that by design or am i doing something wrong ?