StackOverflow when saving

StackOverflow when saving

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


mcalhoun posted on Monday, June 28, 2010

I am using CSLA 4, Beta 3.

My scenario is this...A tenant (root object) has many customers and many deals. Each customer has many deals. Each deal has one Tenant and one Customer.

Tenant : BusinessBase
-Id (Guid)
-Customers (CustomerList : BusinessListBase)
-Deals (DealList : BusinessListBase)

TenantScopedBusinessBase : BusinessBase
-Id (Guid)
-Name (String)
-Tenant (Tenant)

Deal : TenantScopedBusinessBase
-Id (Guid) - Inherited from TenantScopedBusinessBase 
-Tenant (Tenant) - Inherited from TenantScopedBusinessBase
-Customer (Customer : BusinessBase)

Customer : TenantScopedBusinessBase
-Id (Guid) - Inherited from TenantScopedBusinessBase 
-Tenant (Tenant) - Inherited from TenantScopedBusinessBase 
-Deals (DealList : BusinessListBase)

If I attempt to Save the Tenant object, I get a System.StackOverflowException on RaiseChildChanged(e.ChildObject, e.PropertyChangedArgs, e.CollectionChangedArgs) of the Child_Changed method in ObservableBindingList.

If I remove the "Deals" property from the customer object, the same code works just fine. I'm confused...is there some circular reference that I'm missing?

Thanks,
Matt

RockfordLhotka replied on Monday, June 28, 2010

A given object can have exactly one parent. Your object model doesn't indicate whether you are "re-parenting" objects or not, but it certainly seems like such a thing could happen - either trying to have a dual parent or switching parents.

Dual parenting is just not supported, and there's no way to make it work.

Switching parents is possible, but is tricky because BusinessListBase doesn't normally allow you to remove an object without it being marked for deletion and moved to the deletedList.

Copyright (c) Marimer LLC