Relationships
The relationships section is where you can configure, for your dbMapping, the database tables relationship, represented by a foreign key constraint.
If this section is not used to define the relationships between your entities, by default, the Entity Framework will create the relationships through its conventions. However, this section is useful and can be used when relationships do not follow these conventions and manual configuration is required through the Fluent API, such as: creating relationships that target an alternate key to the main entity.
To learn more about Entity Framework conventions and relationship configuration through the Fluent API, see: Relationships | Microsoft Docs
Fields
A relationship contains the following fields to be defined:
ChildEntityName
The name of business entity that will be related with to the dbMapping entity. This refers to the child entity.
Requirements Rules:
- Is Required;
- The name must exist in Entities list in the current model;
- See Entity section for more details.
- There must be a dbMapping for this entity in the current model;
- See DbMapping section for more details.
Example:
1 2 |
|
IsRequired
It allows configuring whether the relationship is required or optional.
This is most useful when you are using a shadow state foreign key.
The default value is 'true'.
Example:
1 2 3 |
|
Type
The relationship type between objects.
Possible types are:
- OneToOne
- OneToMany
Note
For many-to-many relationships, it is necessary to create a new entity that references the other two relationship entities.
Requirements Rules:
- Must be an Allowed valid Type, according to the types informed above
Example:
1 2 3 4 |
|
ParentPropertyName
The property name of the parent entity, to create the relationship.
Requirements Rules:
- Is Required;
- The property must exist on the parent entity;
- The property type must be valid for the relationship, according to the rules below:
- If the relationship type is 'OneToOne': The property must be of the same type as the child entity, representing a relationship between them.
- If the relationship type is 'OneToMany': The property must be a collection of the same type as the child entity, representing a relationship between them.
Example:
1 2 3 4 5 |
|
ChildPropertyName
The property name of the child entity, to create the relationship.
Requirements Rules:
- Is Required;
- The property must exist on the parent entity;
- The property must be of the same type as the parent entity, representing a relationship between them
Example:
1 2 3 4 5 6 |
|
ForeignKeyProperty
It allows configuring which property should be used as the foreign key property for a given relationship.
Requirements Rules:
- Is Required;
- The property name must exist for the entity defined in ChildEntityName in the current relationship;
- The property type must be the same as the KeyType of the parent entity
Example:
1 2 3 4 5 6 7 |
|