all groups > visual studio .net general > november 2006 >
You're in the

visual studio .net general

group:

VS 2005 Class designer : How to have 1 to many association?


VS 2005 Class designer : How to have 1 to many association? jdlwright NO[at]SPAM gmail.com
11/11/2006 1:24:40 PM
visual studio .net general:
Hi, I've just started using the class designer. However after much
googling I can't find how to do a 1 to many association between two
types.

If I do a 1 to 1, it adds a property to one class. That's fine, so
logically you might thing 1 to many would be

classA{

public Collection<classB> ClassBs{
get{...}
set{...}
}
}

it doesnt recognise that as an association.

How do I do a 1 to many? Do I have to have a 1 to 1 assoc. to a
collection subclass and a 1 to 1 from the collection to classB?

Thanks
Jim
RE: VS 2005 Class designer : How to have 1 to many association? William Sullivan
11/20/2006 8:50:02 AM
According to MSDN:
How to: Visualize a Collection Association in Class Designer

Properties and fields that are collections of other types can be displayed
on the class diagram as a collection association. Unlike a regular
association, which displays a field or property as a line linking the owning
class to the field's type, a collection association is displayed as a line
linking the owning class to the collected type.

To create a collection association
In code, create a property or field whose type is itself a strongly-typed
collection.
In the class diagram, expand the class so that properties and fields are
shown.
In the class, right-click the field or property and choose Show as
Collection Association.
The property or field is shown as an association line linking to the
collected type.
___________________________________________________________________

HOWEVER there may be a bug when it comes to generic collections where this
fails. This might be your problem. If it doesn't work, make sure to fill
out a bug report.

Also, there are some power toys for the modeler, not sure if this will help
you, but check it out anyway:
PowerToys for the Visual Studio 2005 Class Designer and Distributed System
Designers: Workspace Home (gotdotnet)
http://www.gotdotnet.com/workspaces/workspace.aspx?id=fe72608b-2b28-4cc1-9866-ea6f805f45f3

[quoted text, click to view]
Re: VS 2005 Class designer : How to have 1 to many association? jdlwright NO[at]SPAM gmail.com
11/21/2006 11:32:58 AM
Thanks!

[quoted text, click to view]
AddThis Social Bookmark Button