How to: create a new Editable Child Object and add it as property of Editable Root Object

How to: create a new Editable Child Object and add it as property of Editable Root Object

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


superkuton posted on Tuesday, November 23, 2010

I am still learning to use the framework.

I have created an editable child object which is a property of an Editable Root Object.

In the Candidate ERO, I declared the ECO CandidateEmail as follows:

Private Shared CandidateEmailProperty As PropertyInfo(Of CandidateEmail) = RegisterProperty(New PropertyInfo(Of CandidateEmail)("CandidateEmaill"))
    Public ReadOnly Property CandidateEmail() As CandidateEmail
        Get
            If Not FieldManager.FieldExists(CandidateEmailProperty) Then
                LoadProperty(Of CandidateEmail)(CandidateEmailProperty, CandidateEmail.NewCandidateEmail())
            End If
            Return GetProperty(Of CandidateEmail)(CandidateEmailProperty)
        End Get
    End Property

 

In the ECO, I included the following function:

 

 <RunLocal()> _
    Protected Overrides Sub Child_Create()
        LoadProperty(Of Integer)(IDProperty, -1)
        LoadProperty(Of Integer)(ContactIDProperty, 1)
        LoadProperty(Of Integer)(TypeIDProperty, 1)
        BusinessRules.CheckRules()
        MyBase.Child_Create()
    End Sub

 

Using a breakpoint, I saw that the ERO is not entering the   If Not FieldManager.FieldExists... when there is not ECO.

Please help. thank you.

JonnyBee replied on Tuesday, November 23, 2010

Hi,

You are using LazyLoading - ie the ECO is not instantiated until you try to get the property in the ERO in the UI or another object.

BTW: Windows Forms databinding does not understand the concept of 1 : 1 relationship between objects.  So I refer to "flatten" the hierarchy in my BOs to not inckude 1:1 relationships. 

 

superkuton replied on Tuesday, November 23, 2010

Thanks JonnyBee.

 

Yeah, you've hit my problem. I am implementing a 1:1 relationship in my BO.

What are my options then, aside from your preference to "flatten" the hierarchy?

 

JonnyBee replied on Tuesday, November 23, 2010

Well, you _can_ consider the objects as separate objects with separate BindingSources but you cannot use the "nested" BindingSources and must be careful on how you define the bindings in your Forms.

So, I prefer to flatten the hierarchy in my own BOs.

 

 

 

Copyright (c) Marimer LLC