Hi!
When I create a new child object I eant it to read a id property from parent object
so I do like this
[RunLocal]
protected override void DataPortal_Create(Object criteria)
{
MarkAsChild();
this.ClientID = ((Client)this.parent).ClientID;
}
but the result is a exception because parent is null!
Any idea?
Regards
The parent is not set until the child has been added to the collection, which means you can't obtain the parent reference when you first create the child. Secondly, if I am not mistaken the parent refers to the childs collection class not the parent it was created under.
eg.
Client.Childs.Child - the parent to child would be Childs not Client
If you are requiring the ClientID from client it us usually passed as a reference when you persist the data.
Thank you for your answer.
But I must ask about this:
"parent refers to the childs collection class not the parent it was created under"
"Client.Childs.Child - the parent to child would be Childs not Client"
I have a Root editable object called Client now this Client has a child editable list called ContactCollection which is a collection of child object Contact
now which one is correct:
1-Client is parent for boyh ContactCollection and Contact
2-Client is parent for ContactCollection and ContactCollection is parent to Contact
Because I am using the codesmith to generate CSLA code and when you create a clid collection or child object it aslks for type of parent and I always have given Client as parent for both Contact and contactcollection and the generated code has worked correct!
Regards
I don't know what your CodeSmith templates are doing but if Contact is derived from BusinessBase then it will have a protected property called Parent. That is a reference to ContactCollection. You need to do something extra if you want a reference to Client. As I suggested in my previous post, I pass a reference to Client into ContactCollection, expose that Client as a property and then within Contact, I can get Client with something like.shahram:
I have a Root editable object called Client now this Client has a child editable list called ContactCollection which is a collection of child object Contactnow which one is correct:
1-Client is parent for boyh ContactCollection and Contact
2-Client is parent for ContactCollection and ContactCollection is parent to Contact
Because I am using the codesmith to generate CSLA code and when you create a clid collection or child object it aslks for type of parent and I always have given Client as parent for both Contact and contactcollection and the generated code has worked correct!
Client client = ((ContactCollection) this.Parent).Client
Ross
Copyright (c) Marimer LLC