CSLA 1.53 - Collection Object error during Fetch

CSLA 1.53 - Collection Object error during Fetch

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


Q Johnson posted on Friday, October 27, 2006

The code in my GetCollection shared method is trivial - I added the Try/Catch just to catch the problem at the source:

Private Sub Fetch(ByVal dr As SafeDataReader)

' create a child object for each row in the data source, this guy is only

' called by his own Shared Method - so Private works fine

While dr.Read

Try

List.Add(RenewalNotice.GetRenewalNotice(dr))

Catch ex As Exception

MsgBox(ex.ToString)

End Try

End While

End Sub

Every time List.Add() is called the following error msg is generated (it is line 162):

System.Exception: Parent value can only be set for child objects
   at CSLA.BusinessBase.SetParent(BusinessCollectionBase parent) in C:\Visual Studio Projects\CSLA_1_52\Csla10\CSLA\BusinessBase.vb:line 239
   at CSLA.BusinessCollectionBase.OnInsert(Int32 index, Object value) in C:\Visual Studio Projects\CSLA_1_52\Csla10\CSLA\BusinessCollectionBase.vb:line 425
   at System.Collections.CollectionBase.System.Collections.IList.Add(Object value)
   at TagTrackerLibrary.RenewalNoticeCollection.Fetch(SafeDataReader dr) in C:\Visual Studio Projects\TagTracker\TagTrackerLibrary\RenewalNoticeCollection.vb:line 162

What am I doing wrong here?

Thanks,

ajj3085 replied on Friday, October 27, 2006

Your private constructor in RenewalNotice should be calling MarkAsChild.

Q Johnson replied on Friday, October 27, 2006

Bless you! Bless you!

I actually looked at that possibility on the collection class, but not on the child class. 

The really alarming thing here for me is that this is generated code.  I made a template six or eight months from which this one is a descendant and I can't figure out where I've screwed it up.  But I better be very careful about re-generating any of my recent projects until I do a little research, eh?

Thanks so very much. 

 

Copyright (c) Marimer LLC