Starts in:
3 DAYS
9 HRS
43 MIN
53 SEC
Starts in:
3 D
9 H
43 M
53 S

Master-Detail Relationship

The Master-Detail (or Master-Child) relationship refers to a hierarchical connection between two entities, where one entity (the master or parent entity) influences or controls the behavior or properties of another element (the child entity) relationship. The relationship between Order - Order Lines and Invoice - Invoice Items can be considered as examples of a master-detail relationship.

In this relationship, the master entity contains unique records that act as the main source of the information. On the other hand, the child entity contains related records that are associated with a single record in the master entity. In other words, the child entity contains detailed information about the master entity.

Creating Master-Detail Relationship

ABP Suite allows you to create a master-detail relationship with a few clicks. It generates the necessary code for the master and detail tables, including the foreign key relationship between the two tables.

To establish a master-detail relationship, you can apply the following steps:

1-) Creating the master entity:

You need to specify the Entity type as Master (default). Then, provide the meta data of your entity, establish a one-to-many or many-to-many relationship if you want, and generate the entity.

2-) Creating the child entity and associating it with a master entity:

Create a child entity, specify the Entity type as Child, and associate it with a master entity. In the figure above, you can see an example of, a child entity OrderLine with the associated master entity Order. When you specify the Entity type as Child, then the UI and tests will not be generated for the child entity and instead, all of the orchestration of the entity will be delegated to its master entity.

Application services will be generated for the child entity, so it's possible for you to consume its endpoints and create-update-list or delete the child entity specifically. Suite also respects your multi-tenancy selection and sets the child entity as a multi-tenant entity, if the master entity has multi-tenancy enabled.

Note: Child entities are not a good candidate to establish a many-to-many relationship and therefore that's disabled in the Suite UI. So, you can't create a many-to-many relationship for child entities, but you can create a one-to-many relationship.

After providing the other meta data of your entity, click the "Save and Generate" button.

3-) Run the application and see the master-child relationship has been established:

That's it! These were the only required steps: "First, create the master entity, and then create the child entity and associate it with a master entity" and now, you're ready to go.

Run the application, and navigate to the page of your master entity. If you have granted all related permissions, you will see the child data-grids and will be able to collapse/uncollapse and see the details. You can also create-update or delete the child entity records from these child grids:

Note: Detail rows are shown in tabs as can be seen in the figure above, and that means that you can have multiple child entities that are associated with the same master entity. You just need to apply the steps above to establish the master-child relationship.


Contributors


Last updated: July 31, 2024 Edit this page on GitHub

Was this page helpful?

Please make a selection.

To help us improve, please share your reason for the negative feedback in the field below.

Please enter a note.

Thank you for your valuable feedback!

Please note that although we cannot respond to feedback, our team will use your comments to improve the experience.

In this document
Community Talks

What’s New with .NET 9 & ABP 9?

21 Nov, 17:00
Online
Register Now
Mastering ABP Framework Book
Mastering ABP Framework

This book will help you gain a complete understanding of the framework and modern web application development techniques.

Learn More