Lazy loading error when 2 properties the same object

Lazy loading error when 2 properties the same object

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


Nemisis posted on Friday, April 17, 2009

I have a parent object that uses lazy loading on alot of fields. I am only using lazy loading, because on this particular object, not all properties will be accessed by a user so seems pointless to loading all 50 objects, when the user will only ever see and use 2.

My problem is that when items are added to the ColumnList property within either Child1 or Child2, it reflects in the other child, if the other child has already been loaded?? If only 1 child exists, it works fine. Both appear to load correctly when they are first accessed, as in they both do not exist when i first access them, and the GetChild method is called.

Anyone got any clues, i wondered if this is something to do with managed fields?

Here is the sample code, i am using the managed fields option. This is only using 2 properties, my real object has over 50 of these childs, all the same, just holding different lists, but of the same type.

Public Class ParentObject
Inherits BusinessBase(Of ParentObject)

Private Shared Child1Property As PropertyInfo(Of ChildObject) = RegisterProperty(GetType(ParentObject), New PropertyInfo(Of ChildObject)("Child1"))
Public ReadOnly Property Child1() As ChildObject
Get
If Not FieldManager.FieldExists(Child1Property) Then
LoadProperty(Child1Property, ChildObject.GetObject)
End If
Return GetProperty(Of ChildObject)(Child1Property)
End Get
End Property

Private Shared Child2Property As PropertyInfo(Of ChildObject) = RegisterProperty(GetType(ParentObject), New PropertyInfo(Of ChildObject)("Child2"))
Public ReadOnly Property Child2() As ChildObject
Get
If Not FieldManager.FieldExists(Child2Property) Then
LoadProperty(Child2Property, ChildObject.GetObject)
End If
Return GetProperty(Of ChildObject)(Child2Property)
End Get
End Property
End Class

Public Class ChildObject
Inherits BusinessBase(Of ChildObject)

' SOME OTHER PROPERTIES HERE

Private Shared ColumnListProperty As PropertyInfo(Of BaseGridColumnList) = RegisterProperty(GetType(ChildObject), New BSLPropertyInfo(Of BaseGridColumnList)("ColumnList", BaseGridColumnList.NewGridColumnList))
Public Overrides Property ColumnList() As BaseGridColumnList
Get
Return GetProperty(ColumnListProperty)
End Get
Set(ByVal value As BaseGridColumnList)
LoadProperty(ColumnListProperty, value)
End Set
End Property

Public Shared Function GetObject() As ChildObject
' call fetch method here
' items will be added to columnlist
' if no values are in the database
End Function

Private Overloads Sub DataPortal_Fetch(ByVal criteria As SingleCriteria(Of Profile, String))

' mark as child, as using lazy loading technique
MarkAsChild()

' Add items to ColumnList here
End Function

End Class

RockfordLhotka replied on Monday, April 20, 2009

Is this with a local or remote data portal?

And what version of CSLA?

And are you using inheritance (do you have a custom base class)?

Copyright (c) Marimer LLC