Allow multiple parents for children

Mar 8, 2011 at 2:24 PM

Hi Charleh

[quoting Charleh]

Allow multiple parents for children either by interface or by multi-parent dataportal methods

If this is already done by the object relation builder, then I apologise as I've not really got to grips with it yet.

Nobody likes creating multiple objects which do the same thing - take for example a 'notes' collection which takes two keys 'ID' and 'Area'. The best way I can get CSLAGenFork to represent my objects correctly is to add an interface as an object and then create my child 'notes' collection which has the interface as it's parent. It's a hack but it works. When this is done, all you need to do is add a new child collection property to your objects and make sure it's of the correct type (childnotecollection), and also make sure the object implements the interface.

[end of quote]

On this question, please refer to a very recent forum thread. Csla object structure isn't supposed to allow for children to have multiple parents.

Having said that, I think you are talking about something that is quite common on any business application: different objects contain children of the same basic type. By basic type I mean the same behaviour but also the same data. 

Does CGF allows some way to do it without editing the generated code? If so, I presume there is room for improvements. Can you send a sample CGF project?


Mar 9, 2011 at 8:58 AM
Edited Mar 9, 2011 at 8:59 AM

Hi Tiago,

I think from Rocky's post, he is saying that you cannot support a single instance of a child that is shared amongst multiple parents simultaneously.

Just to clarify, I'm talking about having a child to multiple parent relationship only in structure - instances of children in different parents will be unique.

Technically since a parent reference is of type IParent, the parent isn't constrained to a particular type. As long as the child implements the correct functionality, it should be able to support multiple parents

My best experience of this is via an interface, and I managed to get CSLAGenFork to generate code for this, in a limited sense.

I'll create a sample CSLAGenFork project to show the way I managed to get it to work - it does require implementation of the interface in the non-generated partial class file, but it saves a lot of work

I'll upload the project shortly

Mar 9, 2011 at 11:08 AM

Hi tiago - I can mail you this project unless you know of a good place to attach it (I can't see most file hosting sites, our control policies are strict). Are you on VS2010? It mostly works - with some small '1 time' modification to the generated code for the child, and a tweak to the generated code for the parents. These could probably be fixed in the templates.

I can't seem to PM you on CodePlex - it throws an 'undefined' error on the page! (maybe they need to update their templates :))

Mar 9, 2011 at 9:24 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Mar 9, 2011 at 9:25 PM
Edited Mar 9, 2011 at 9:25 PM

Please attach the sample to work item #459.

Mar 10, 2011 at 2:04 PM

FYI - sample added