Share via

Bringing data from DAL to UI

ANB 181 Reputation points
2022-01-25T16:53:14.203+00:00

I'm doing a simple task, but thinking about what would be the best approach.
Assuming I have 2 tables:

Product
Code, Name, Manufacturer, Year, Stock

ProductSpecs
Color, Weight, Height, Width, Value, Commission

So in my frontend I want to display, Code, Name, Color and Weight.
Ex:
001, Shelf, Black, 10kg
001, Shelf, Gray, 10kg
003, Closet, Blue, 15kg

Considering a multi-layer application (DAL, Services, UI), what would be the best approach?

  1. Whole objects
    The services layer brings the entire Product object (coming from DAL - Stored Procedure Product)
    The services layer brings the entire ProductSpecs object (from DAL - Stored Procedure ProductSpecs).
    Then in the services layer, we create a DTO or T class and gather the information coming from both services.
    The UI layer calls the API that would bring this DTO as a single object.
    Doubts: Bringing whole objects from DAL won't be harmful, since I only need a few ?
  2. Join DAL
    We created a stored procedure that would JOIN the 2 tables mentioned above with only the desired fields and we would create a DTO with all the properties to receive this JOIN.
    The UI layer calls the API returning this DTO as a single object.
    Doubts: If I create stored procedures with specific JOIN's, won't it force me to have a large number of stored procedures for each variation of objects that I will need on each page of my application?
  3. Various Requests
    The Product services layer returns the entire object.
    The services ProductSpecs returns the entire object.
    2 requests are made through the API, 1 for product and another for product specs.
    The UI receives the 2 objects separately.
    Doubts: Doesn't making multiple requests end up being worse than making a single call returning a larger object?

What is your opinion ?
Hugs

Developer technologies | ASP.NET Core | Other

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.