This website is intended as archive for old content and forums.
Please visit http://opf3.codeplex.com for the project's new website.

General Discussion

FORUM TOPIC

What is Opf3? Why is Opf3? How is Opf3? All these burning questions and issues discussed here.

RSS
Dave Nespoli
Posted on the 10/19/06 10:11 PM
Many-Many setter
Reply Quote
 Hi,

I am trying to find the easiest and most simple way to write the setter for a many to many relationship. My primary concern is to keep it clean and simple as I need to implement this code for each setter. I am simply creating a list of related objects (pulled from a check box list) and passing that in to the setter. The hard (well not really) part of this is making sure the removed items get marked for deletion. I am not super concerned with performance so, here is what I came up with:

Set(ByVal value As IList(Of T))
_ObjectSetHolder(Of T).InnerObject.RemoveAll()
_ObjectSetHolder(Of T).InnerObject = New ObjectSet(Of T)(value)
End Set

This obviously does some uneeded deletes, but it's the most simple way I can see.

Any thoughts or suggestions or better approaches?

-Dave

Christian Liensberger [Moderator]
Posted on the 10/20/06 7:17 AM
RE: Many-Many setter
Reply Quote
 Seems quite an OK approach, since you don't conceirn about speed... What I often suggest is to remove the setter and do the remove in the UI. If the user removes an object, just call the Remove of the ObjectSet with giving it the object instance.

Christian

Dave Nespoli
Posted on the 10/20/06 1:29 PM
RE: Many-Many setter
Reply Quote
 Yes. That is a cleaner approach if possible.

I have my checkboxlist nested in a series of UserControls, and rather than having to popogate the 'uncheck' events I was just trying to retrieve a new list of relations from the control and simply pass them in to the many-many. In any case, I suppose I am just looking for a simple way to replace a relation list with a new realtion list and not have determine the deletions manually.

An alternative approach would be to use the set operations of the ObjectSet to accomplish the same, but the set operations do not move elements to the removed list. For example if the Intersect method moved elements which were pulled off the list to the removedlist then I could do the following:

set
{
   ObjectSet.Intersect(value);
   ObjectSet.Union(value);
}



Christian Liensberger [Moderator]
Posted on the 10/20/06 2:28 PM
RE: Many-Many setter
Reply Quote
 This issue was discussed in Messenger.

All times are in GMT.