Child object into two different root objects

Child object into two different root objects

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


remitos posted on Friday, February 20, 2009

Hi,

I have the following situation. I have two EditableRootList (ListA and ListB). I then add one child object (ChildA) into ListA. List A countains many other objects.

I then want to add a reference of ChildA into ListB (for example to show a sub-list of ListA into another UI control). Everything works fine.

But when I want to save ListA, I want to disable list events by setting RaiseListChangedEvents to false for ListA during the save process (for faster performance). But the ListChangedEvents are still called for ListB countaining ChildA too (which is normal). Is there a way to prevent that? I would like to set RaiseListChangedEvents to false for every list my child object is into.

Am I using root-child relation in a wrong way?

Thanks.

RockfordLhotka replied on Saturday, February 21, 2009

CSLA doesn't support the idea of a child having multiple parents at the same time. You'll run into issues not only with eventing, but also with n-level undo, data binding, etc.

Programmer1987 replied on Monday, February 23, 2009

I have this case in my current project
I have window for each parent [P1,P2] and I want to display the childList {CList} in each window

But I will let the user To edit the child from one Parent P1
and Just display them in the Second Parent Window P2

Can we do that ? and if yes what is the main steps only and thanks a lot

JonnyBee replied on Monday, February 23, 2009

Hi,

You should use FilteredBindingList or LINQ to create a "subquery" list of objects rather than having a separate ListB (depends on which UI technology, CSLA version  and .NET version you are using).

As Rocky stated -  Child objects can/should only exist under one parent list - use FBL or LINQ to create a "filtered" view for other usages.

/jonnybee

Programmer1987 replied on Monday, February 23, 2009


okay Do you mean ?

I will use FilteredBindingList Or Linq In the Parent class that I want to just display its child

so as the result this will not considered as Parent

the Second Parent Will be the Real Parent .

Is this right ? :)

remitos replied on Thursday, February 26, 2009

I tried using FilteredBindingList but I cannot achieve exactly what I want.

To simplify the case, imagine that I have an EditableRootList showed in a data grid. I also want to take the current selection in the grid (one or more items) and show these items in a Property Grid (to edit a property to the same value for all my selection).

How can I achieve that with CSLA objects? Taking a certain sub-set of items (not necessarily filtered by any rule) and do other task with this sub-set (like modifying data).

Thank you

tmg4340 replied on Thursday, February 26, 2009

As Rocky has mentioned, CSLA doesn't support the concept of one object with multiple parents.  While the ERLB object is a little bit of a special case, it still follows the same rules.

In this instance, probably the easiest thing to do is to create a new collection with your subset of objects, and then you would edit that new collection.  This new collection would not be populated from your ERLB - it would re-fetch the data from the database.  You would also need to create a link in your application so that when the new collection is updated back to the database, your ERLB re-loads and gets the new values.

HTH

- Scott

Copyright (c) Marimer LLC