I'm currently building an API and a web app for an internal warehouse system using NET Core. I have the core entity structure, that goes like this:
"Material" has many "MaterialSubtypes" has many "MaterialClasses" has many "Packs".
Now, I need to create a list, representing a single sale. It can include lots of packs of different materials. The user should be able to add or remove packs to a sale as it is being prepared. The problem is that I also need to show the user the list of all materials hierarchy that the sale contains, as well as the sum of "Quantity" field of all packs on each sublevel. This quantity is supposed to be updated dynamically in a client app.
What is the most efficient way to do this? Should I just add all packs to a sale, and then, on every GET request, Include everything and recalculate all sums via foreach loops? Or should I create separate entities for Material->MaterialSubtype->MaterialClass within the Sale and update them each time a Pack is added? None of that seems optimal, but I can't think of anything else.