Accessing data upwards

Accessing data upwards

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


whelzer posted on Friday, June 12, 2009

Hi,

I got the following situation

Customer (BB)
      IndividualList (BLB)
           Individual (BB)

I need access to Customer properties from Individual (within Validation Rules in particluar).

Am using csla 3.5/vb 2008.  Any help much appreciated.
        

Tom_W replied on Saturday, June 13, 2009

This thread covers reading grandparent properties from a grandchild:  http://forums.lhotka.net/forums/thread/27073.aspx


whelzer replied on Saturday, June 13, 2009

Tom,

Thanks for te reply, I had spotted that thread but its not happening for me, I've put this in the chld list (Individuals):

Friend ReadOnly Property MyParent() As CustomerEdit
            Get
                Return Me.Parent
            End Get

        End Property

And in the Individual object I've got this in a rule method:

 If Not target.Parent Is Nothing Then

                Dim objParent As Individuals = CType(target.Parent, Individuals)

                If objParent.MyParent.SourceId = 1 Then

                    If target._email = "" Then
                        e.Description = "Email Required."
                        Return False
                    End If

                End If


                Return True

            End If

I get a "Object reference not set to an instance of an object" exception when I attempt to access the Myparent.SourceId ..think it could be small enough issue - I've just spent far too long looking at it!!

Tom_W replied on Saturday, June 13, 2009

What you're doing looks right to me.  Is there any chance that 'target' hasn't been set correctly?  I'm assuming that target is a parameter passed into the rule function and is of type Individual? 

If you stick a breakpoint in code somewhere (before calling the rule) can you inspect the parent Customer and check that it's Individuals collection has correctly got it's parent set to the Customer collection?

If that works, then if you stick a breakpoint in the rule, and then look at target and target.Parent do these have values, and do they refer to the same objects as you saw from the breakpoint in the Individuals collection's constructor?


whelzer replied on Sunday, June 14, 2009

Its the new property on Individuals.

 Friend ReadOnly Property MyParent() As CustomerEdit
            Get
                Return Me.Parent
            End Get

        End Property

It always returns nothing - for existing objects, when creating new ones, etc.

Whilst I'm using v 3.52 I still using 3.0.4 syntax could this be a factor?

Has anybody successfully implemented this structure to access Root Parent properties.

If there are better approaches I'll happily look at them (events? ) I badly need this working asap.

Thanks

acgritt replied on Monday, June 15, 2009

One thing you could try is hooking up the On List Changed event to the list of Individuals in the Customer object and then when a child is modified catch the event and have the Validation Rule exist on your Customer object.  You just have to make sure that you reconnect the OnListChanged event in the override for OnDeserialized so that when the Business Object go across the wire it will reset the event hookup.

whelzer replied on Monday, June 15, 2009

Came up with a horrible solution - I put SourceId on object Individual, in the property of SourceId on CustomerEdit...

For each i as individual in _myIndividuals
    i.SourceId = _SourceId
next i

Its not pretty but it done the job...for now, will only ever have 3 or 4 individuals max.

We plan on converting this set of objects to use 3.52/3.6 properly in about a months time - so I'll revisit issue then. Hopefully I'll be up to stratch on the new property Info stuff and the new Parent/Child features.


Tom_W replied on Tuesday, June 16, 2009

Congratulations on finding a solution.

I finally got a chance to try this with ProjectTracker and it seemed like the Parent property had the same issue with returning nothing when I was looking at the ProjectResources collection, so I'm guessing there's a step we're missing somewhere to get the Parent property working correctly.

Copyright (c) Marimer LLC