Page 1 of 1

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:

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();
}
I get the following error:

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
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 ?

update

Posted: Tue 03 Mar 2009 15:26
I've tried to manually retrieve the parent object (walnumber) to attach it to the childobject like this:

Code: Select all

employee.Walnumber = walnumber;

in other words:

childboject.parentobject = parentobject
But that gives me the following error:

Code: Select all

Line 6528:            set
Line 6529:            {
Line 6530:                Walnumber previousValue = this._Walnumber.Entity;
Line 6531:                if (((previousValue != value)
Line 6532:                            || (this._Walnumber.HasLoadedOrAssignedValue == false)))

small update2

Posted: Tue 03 Mar 2009 16:00
Please check my old topic at

http://devart.com/forums/viewtopic.php?p=41604#41604

(about attaching childobjects to a parentobject and insert them in one move)

This does not seem to work either.

The intellisense does not prompt me for the .add method

example:

Code: Select all

Parentobject.childobjects.add(chilobject)

Posted: Wed 04 Mar 2009 11:56
by AndreyR
Could you please send me (support * devart * com, topic "LINQ: Dispoesd context") a small test project illustrating the problem?
As for the post http://devart.com/forums/viewtopic.php?p=41604#41604, the bug was already fixed and the fix is included in the current build. Maybe problem occurs because of an old Devart.Data.Linq.dll left in GAC after uninstall.
Try uninstalling dotConnect, then removing all Devart.Data.*.dlls from GAC and then reinstalling the current version.

All problems solved with latest version

Posted: Wed 04 Mar 2009 13:55
Hi,

Thanks for your time, but i've installed the latest version and removed all old Dll's from my system.

Everything works fine now !