How to: Create associations between types in Class Designer

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

Association lines in Class Designer show how classes in a diagram are related. An Association line represents a class that is the type of a property or field of another class in your project. Association lines are generally used to illustrate the most important relationships between classes in your project.

While you could display all fields and properties as associations, it makes more sense to show only important members as associations, depending on what you intend to emphasize in the diagram. (You can show less important members as regular members or hide them altogether.)

Note

Class Designer supports only unidirectional associations.

To define an association line in the Class Diagram

  1. In the Toolbox, under Class Designer, select Association.

  2. Draw a line between the two shapes you want to link with an association.

    A new property is created in the first class. This property displays as an association line (not as a property within a compartment in the shape) with a default name. Its type is the shape to which the association line points.

To change the name of an association

On the diagram surface, click the label of the association line and edit it.

Alternatively, follow these steps:

  1. Select the shape that contains the property that is shown as an association.

    The shape obtains focus and its members display in the Class Details and Properties windows.

  2. In either the Class Details or Properties window, edit the name field for that property and press Enter.

    The name is updated in the Class Details window, on the association line, in the Properties window, and in code.

See also