Normal Relationship Editor

The Normal Relationship Editor allows you to add and edit a normal relationship. A normal relationship is a relationship of the type one to many (1:n), many to one (m:1) or one to one (1:1). To open the Normal Relationship Editor to add a new relationship, you can use Project -> New -> Normal Relationship from the main menu, by clicking the New Normal Relationship Editor button on the toolbar, by pressing Ctrl-Shift-N, or by right-clicking on an entity's Relationships node in Project Explorer. You can edit a normal relationship by right-clicking it in the Project Explorer or in the ModelView Editor.

Normal Relationship Editor

The Normal Relationship Editor showing an existing 0..1:n relationship

The Normal Relationship Editor consists of three parts which are described below.

Relationship specifics area

This area allows you to specify which two entities are related to each-other and how many of one side are related to how many of the other side. You should read the area as a single sentence.

Example: to specify the relationship Customer 1:n Order, you should do the following:

  • Specify 0..1 or 1 in the first combo box, first line
  • Specify Customer in the second combo box, first line
  • Specify Many in the first combo box, second line
  • Specify Order in the second combo box, second line

This then reads 0..1 Customer is related to Many Order

Below the combo boxes a checkbox is available, which is enabled when the relationship forms a 1:1 relationship: the checkbox is used to specify which side is the primary key side. In 1:1 relationships this is not always determinable.

To mark the relationship as a model-only relationship, you can check the checkbox Is Model Only. This will mark the relationship as a model-only relationship so it doesn't require a backing Foreign Key constraint in the relational model data. This also means that LLBLGen Pro won't generate a Foreign Key constraint for this relationship during relational model data synchronization.

The relationship specifics area also allows you to specify the values for the Update and Delete rules. The default values for these rules are either obtained from the backing FK Constraint if the relationship is created database-first, otherwise they're obtained from the project settings resp. Default relationship delete rule action and Default relationship update rule action. If a relationship is marked as model only, the Update / Delete rules have no effect, as they're not used in the .NET code.

This area allows you to specify the navigators for both sides of the relationship. These navigators are seen as mapped onto the relationship to create. In our Customer 1:n Order example, the two navigators will be Orders (which is part of the entity Customer) and Customer (which is part of the entity Order). LLBLGen Pro will try to formulate the initial values of the navigators from the entities specified and the navigator patterns specified in the project properties.

If you leave a navigator empty, it's considered 'not there'. This is equal to deleting a navigator from the Project Explorer. Linq to Sql can't deal with empty navigators. It's also recommended to have both navigators defined for all relationships unless you want to have a single-sided relationship. In that case, at least define the navigator for the foreign key side of the relationship.

Field relationships area

This area defines which foreign key fields are related to which primary key fields. You can use this area to choose an existing entity field for being a foreign key field, which can be the case if you want to share a foreign key field among relationships. By default, the editor will specify <Auto create> for 'Fk field' which means a new field will be created in the entity on the foreign key side of the relationship when the relationship is created.

When you're done defining the relationship, press OK to create it.