Wrox Home  
Search P2P Archive for: Go

  Return to Index  

expert_vb_business_objects thread: many-to-many relationships


Message #1 by "Eric" <ericbrandes@h...> on Fri, 28 Feb 2003 00:43:10
The new book directly addresses this many-to-many issue.

My example application is one where there are projects and there are
resources (people).

A resource can be assigned to projects, and of course a project can have
a number of resources. A classic many-to-many relationship.

In the book we create Project, ProjectResources and ProjectResource
classes. We also create Resource, ResourceAssignments and
ResourceAssignment classes. (there's a bit of inheritance for code reuse
in there too)

Ultimately the two collection objects drive off the same core data - the
link table between Project and Resource - but they are different classes
with some different behaviors, etc.

The whole many-to-many thing is complex, and by showing it in the book I
hope to help out. It also has the side effect of showing how to do
regular parent-child relationships, so I was able to cover most common
scenarios in one example.

Rocky

> -----Original Message-----
> From: Eric [mailto:ericbrandes@h...] 
> Sent: Friday, February 28, 2003 12:43 AM
> To: expert_vb_business_objects
> Subject: [expert_vb_business_objects] many-to-many relationships
> 
> 
> In the 'Relational vs Object-oriented Models' posting on your 
> website you 
> discuss the many-to-many relationship between Doctors and Services. 
> 
http://www.lhotka.net/Articles.aspx?id=ff226256-903f-4aee-a921-
8b09ef40901b

It is this type of relationship that I have had troubles with while
using 
the CSLA and I was wondering if the CSLA.NET makes this easier.  The 
problems I've had were not with the load methods [GetServices() or 
GetDoctors()], but rather with the editing of the relationships.  

Requirement:
I want to create an admin form that has the properties of a Doctor as 
well as a list of the Services he/she provides.  On that form, I want to

allow the user to add or remove Services that the Doctor offers and I 
also want the changes persisted only when the user clicks the OK/Apply 
button.

Problem:
Suppose the user loads the admin form for a particular doctor that
offers 
three services. The user wants to remove one Service and add one new 
Service.  Where do these changes get stored in the Doctor object? 

I have tried a couple of approaches to this scenario, but none that I 
have been satisfied with.  One approach was to add two collections to
the 
Services object (newlyAdded and newlyRemoved) and manage it in the 
Services object.  Another approach was to create a wrapper class for the

relationship.  Both these approaches led to other problems and so I was 
hoping that you can shed some light on how this can be better handled in

the CSLA.NET framework. 

As expressed elsewhere in this forum, I too have benefited greatly by 
your Business Object series and can't wait to go through the new one.


  Return to Index