Export (0) Print
Expand All

How to: Create and Modify Associations

[This page is specific to the latest version of the Entity Framework. The latest version is available as the 'Entity Framework' NuGet package. For more information, see Entity Framework Releases and Versioning.]

Associations define relationships between entity types in a conceptual model. Associations can only have two participating entity types, and each participating entity type in the association is known as an End. There can be multiple associations between entity types. Associations are represented on the design surface as a line that connects two entity types. For more information, see Defining and Managing Relationships.

Create an Association

Creating an association with the Entity Designer updates the conceptual model content of the .edmx file. For more information about the content of an .edmx file, see .edmx File Overview. After creating an association, you must create the mappings for the association. For more information, see How to: Create and Edit Association Mappings.

To create an association by using the Add Association dialog box

  1. Right-click an empty area of the design surface, point to Add , and select Association .

    The Add Association dialog box appears.

  2. Fill in the settings for the association.

    noteNote:
    You can choose to not add navigation properties or foreign key properties to the entities at the ends of the association by clearing the Navigation Property and Add foreign key properties to the <entity type name> Entity checkboxes. If you add only one navigation property, the association will be traversable in only one direction. If you add no navigation properties, you must choose to add foreign key properties in order to access entities at the ends of the association. For many-to-many (*:*) and one-to-one (1:1) associations, you cannot add foreign keys to the entities. For more information, see Defining and Managing Relationships.

  3. Click OK .

To create an association using the Toolbox

  1. Click the Association control in the Toolbox.

  2. Select the entities to include in the association by clicking an entity in the design surface and then clicking another entity on the design surface.

    The New Association dialog box appears.

  3. Fill in the settings for the association:

    • Specify a name for the new association.

    • Select the multiplicity for each entity.

    • Specify the navigation property name for each entity.

  4. Click OK .

noteNote:
Adding an association with the Toolbox automatically adds navigation properties to the entity types at the ends of the association. Foreign key properties are not added to the entity types. For more information, see How to: Edit and Delete Navigation Properties and Defining and Managing Relationships.

Delete an Association

Deleting an association as described in the procedure below will only delete the association from your conceptual model. To delete the corresponding association from your storage model, see How to: Delete Objects from the Storage Model.

To delete an association

  • Right-click the association on the Entity Designer surface and select Delete .

    -or-

  • Select one or more associations and press the DELETE key.

See Also




Build Date:

2013-06-19
Show:
© 2014 Microsoft