How do you set the ParentId to a new Child?

How do you set the ParentId to a new Child?

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


superkuton posted on Wednesday, July 08, 2009

I have the following objects:

- Student Object (EditableRoot)
   -  ContactAddressList (Editable Child List)
      -  ContactAddress (Editable Child)


I implemented an AddnewCore override, and set the AllowNew = True in the private constructor.
My problem is in the creation of the child object. In my code, I have the following:

..........
 Private Overloads Sub Child_Create()
        LoadProperty(Of Integer)(IDProperty, -1)
        LoadProperty(Of Guid)(ParentIDProperty, ?HOW?)
        LoadProperty(Of String)(OtherProperty, defaultvalue)
        ValidationRules.CheckRules()
    End Sub
...............
    Private Sub Child_Insert()
        Using ctx = ContextManager(...)
            If IsSelfDirty Then
                ctx.DataContext.ContactAddressInsert( _
                ReadProperty(Of Integer)(IDProperty), _
                ReadProperty(Of Guid)(ParentIDProperty), _
                ReadProperty(Of String)(OtherProperty))
            End If
        End Using
    End Sub


How can I set the ParentID reference?
Thanks.

Vinodonly replied on Wednesday, July 08, 2009

First of all the Child_Insert will auto pass the parent object.. So you can use that object to get key... See PTTracker for that...

I don't think you need the parent property in Child_Create

But if that is the case then you can use this.Parent to get reference for parent object and then set the appropriate property..

You might have to cast it to the proper type before using..

superkuton replied on Wednesday, July 08, 2009

Thank you for helping me again vinodonly.

I have the following db tables:

  1. Person (PersonIntID, ProfileGUID, etc.)
  2. Organization (OrganizationIntID, ProfileGUID, etc.)
  3. ContactAddress (ContactAddressIntID, ProfileGUID, etc)
  4. ContactNumber (ContactNumberIntID, ProfileGUID, etc)
  5. ContactPerson (ContactPersonIntID, ProfileGUID, etc)

IntIDs are primary, identity keys. The GUIDs served as the foreign keys to the Contact... tables (3,4,5).

I have created the Person and Organization separately because they have different field requirements. I used the GUIDs to "connect" them to the Contact... tables. Therefore, they are not automatically assigned by any db relationship. I don't know if this was a good design, but I simply avoided the creation of another set of (3) Contact... tables.

The contact business objects are managed by an editable root (PersonContact) object. The Contact... tables are all editable child collection objects.

In my UI, I present the PersonContactEditDialog where the PersonContact is "read-only" because it is managed by another object/context/form. The 3 Contact... objects are presented in 3 datagridviews which are all editable and set to allownew and so on.

---
First, if there is a better db design that you can suggest, I'd be glad to re-structure the db tables as of this early stage of development.

Second, (please read on), how do I use the this.parent? Are there better ways or techniques to manage the parent and children biz objects?

Third, are there better options to present them in a UI?

---
As you can observe, I am totally in-charge of the whole application design and development as this is just a pro-bono work for our school.

Please help me, In doing so, you are also helping our school and all of our students.

Thank you.

Vinodonly replied on Wednesday, July 08, 2009

Actually this forum is for CSLA so I beleive here CSLA related questions should be asked..

I went through your msg quickly and here are some points but it is better to get some books and/or some training to clear the basic concepts..

1. There are varied opinions on using GUID or int, both can be used for setting foreign key relation. Study this more and then you can decide..

2. Pls re-chk if really you will be having multiple Addresses or Multiple Phone Nos ? Maybe you just need one address or maybe 2 phone nos. In that case, you can simplify your db structure.

3. this.parent will give you the ref of the parent object. From all csla child objects this is is avl. So you can use it to get the parent key.

Pls look at the tracker sample, you will understand how it is used..

Copyright (c) Marimer LLC