How to add/edit a relationship

Adding a new relationship

When working database-first, reverse engineering Tables to Entity Definitions will automatically reverse engineer the foreign key constraints between the tables involved to relationships between the created and existing entity definitions. By default, only normal relationships (1:1/m:1/1:n) will be added through reverse engineering from relational model data.

Many-to-many relationships are only added through reverse engineering if the Project Setting Auto add many to many relationships is set to true (default is false). Relationships added through database-first techniques will automatically set the Update/Delete cascade rules with the values defined on the backing Foreign Key Constraint.

To manually add a relationship between two entities, use one of the following options:

  • Right-click on the 'Relationships' node below an entity definition in the Project Explorer and choose either 'New Normal Relationship' (Ctrl-N) or 'New Many-to-Many Relationship' (Ctrl-M) from the context menu. This will bring up the Normal Relationship Editor or the Many-to-Many Relationship Editor with the entity definition owning the Relationships node already pre-selected as the start entity of the relationship.
  • Press Ctrl-Shift-N for a new normal relationship or Ctrl-Shift-M for a new many-to-many relationship. The start entity isn't pre-selected.
  • Choose from the main menu: Project -> New -> Normal Relationship... or Project-> New -> Many-to-Many relationship. With these options, the start entity isn't pre-selected
  • Click the New M:N relationship Button button in the toolbar for a new M:N relationship, and the New normal relationship Button button in the toolbar for a new m:1/1:1/1:n relationship.
  • Use Quick Model to quickly define relationships between two existing or non-existing entities.

Adding a normal relationship also means: specifying the foreign key fields related to the primary key fields (or use the default, which means auto-generate the foreign key fields) and specify the navigator names for both sides.

Edit a relationship

To edit a relationship, right-click the relationship in the Project Explorer and select Edit... from the context menu, or press cntrl-shift-O while a relationship node is selected. Editing a relationship doesn't allow you to specify which entities are involved, but does allow you to specify the foreign key fields, alter the quantity indication per side and edit the navigators.

Mark a normal relationship as 'Model-only'

To mark a normal relationship as model-only (so it doesn't require a backing Foreign Key constraint in the relational model data), you can either right-click it in the Project Explorer and select 'Is Model-Only' to toggle the model-only setting on the relationship or check the checkbox in the Normal Relationship Editor. You can also specify the suffix mo after the relationship definition in Quick Model or right-click the relationship in the ModelView editor.

Editing Update / Delete cascade rules

Every normal relationship defines Update / Delete cascade rules. These rules are initially set to either the value defined on the backing Foreign Key constraint (when they're a product of reverse engineering using database-first functionality) or to the values defined in theĀ  Project Setting Default relationship delete rule action and Default relationship update rule action. The Normal Relationship Editor allows you to alter the values for the Update and Delete cascade rules. Changing the values for these rules will update a backing Foreign Key constraint in with the same values when you synchronize the relational model data using the Synchronization feature (if the schema/catalog has its sync source set to mixed/model).