Orphaned Object

Orphaned Object

Old forum URL: forums.lhotka.net/forums/t/7396.aspx


RedShiftZ posted on Tuesday, August 04, 2009

I have a problem I am not sure how to solve and would like some ideas. This is not strictly a CSLA issue, but I'm hoping the members here can point me in the right direction...

Here is the situation. I have the following structure for my CSLA objects

MyAppointmentList : BusinessListBase<MyAppointmentList, MyAppointment>

which has children...

MyAppointment : Csla.BusinessBase<MyAppointment>

which has a AutoInc int field as Primary Key (AppointmentID).


Simple enough. The list is being used by the DevExpress Scheduling component as a datasource which basically wraps the MyAppointment object with it's own Appointment object via a DevExpress Storage component.

When accessing the DevExpress components, you use their objects which present an interface to get to the original object

MyAppointment appt = (MyAppointment)Appointment.GetSourceObject(DevExpressStorage);

So this gives us the original base Appointment object to deal with.

The problem, When you create a new Appointment, MyAppointment is null until Appointment.Save is called. At that point,
It adds a new MyAppointment to the List and calls

MyAppointmentList = MyAppointmentList.Save
DevExpressStorage.DataSource = MyAppointmentList;

which reloads the base list, Now the Appointment I am working with no longer points where I expect it. It is orphaned as far as I can tell.

Thoughts? I am working up sample code to submit to DevExpress, but I'm sure they will want me to pull CSLA out of the mix...

Thanks,

Jeff Young

cberthold replied on Tuesday, August 04, 2009

I'm pretty sure your having a binding issue.  If you are going to use CSLA with components that are heavily geared towards the BindingSource and DataSets it is highly recommended that you use a BindingSource and follow the RebindUI method of saving objects.  Part of the problem you are experiencing is the complete change of the datasource does indeed change the connection of the Appointment object and will essentially be orphaned.  I think if you use a BindingSource and set the DevExpressStorage.DataSource to the BindingSource and then on the AppointmentsChanged event of the storage fire the RebindUI it will work.  If you are unsure of what that looks like check out the Project Tracker sample.

Copyright (c) Marimer LLC