System.NotSupportedException: Invalid for root objects - use Delete instead

System.NotSupportedException: Invalid for root objects - use Delete instead

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


Hemant posted on Wednesday, May 14, 2014

Hi Friends,

I'm new to CSLA and I'm currently working on one of our project done using CSLA. I'm getting the following exception when trying to remove an item from the collection. I tried the Delete method but that is not affecting the collection. Can you please shed some light on how to address this issue?

System.NotSupportedException was caught

  Message=Invalid for root objects - use Delete instead

  Source=Csla

  StackTrace:

       at Csla.Core.BusinessBase.DeleteChild()

       at Csla.Core.BusinessBase.Csla.Core.IEditableBusinessObject.DeleteChild()

       at Csla.BusinessListBase`2.DeleteChild(C child)

       at Csla.BusinessListBase`2.RemoveItem(Int32 index)

       at System.Collections.ObjectModel.Collection`1.RemoveAt(Int32 index)

 

Thanks,

Hemant.

ajj3085 replied on Wednesday, May 14, 2014

When you create the items as they are added to the list, are you using the DataPortal.ChildCreate for DataPortal.ChildFetch?  If you're using the non-child versions, Csla marks the object as a root meaning it should have no parent, but if its in a list it must be a child.

Hemant replied on Thursday, May 15, 2014

Thanks Andy,

Thank you for the direction. I added MarkAsChild for the collection entries and this solved the issue.

ajj3085 replied on Thursday, May 15, 2014

That will work, but normally the framework calls it for you provide you use FetchChild instead of Fetch on the DataPortal.

Hemant replied on Thursday, May 15, 2014

Thank you for the heads up Andy.

Regards,

Hemant.

Copyright (c) Marimer LLC