MarimerLLC / cslaforum

Discussion forum for CSLA .NET
https://cslanet.com
Other
31 stars 6 forks source link

DTO question #300

Closed Chicagoan2016 closed 7 years ago

Chicagoan2016 commented 7 years ago

Hi All, looking at the samples it appears we have a DTO for every table in the database? is this the recommended approach? What if we have a business objects that is using data fields from three different tables ( using stored proc for data access)? should we create a new DTO or use existing ones? perhaps an example will help :)

kind regards

ghost commented 7 years ago

The way I did this in my last project was as follows:

The DTO for Unit of Work/ViewModel objects might have values from three different tables similar to what you have described. Admin DTO is a 1-1 mapping to my BusinessBase.

rockfordlhotka commented 7 years ago

You can shape the DTO based on what works best for you. There are two primary approaches.

  1. You can have your DAL aggregate all your varied data sources so the DataPortal_XYZ methods invoke one DAL method and get back a DTO that has everything. The DAL hides the fact that the data came from multiple sources.
  2. You can have your DataPortal_XYZ methods interact with multiple DALs, one for each data source. Then the DP_XYZ method gets back multiple DTOs and uses them to populate the business object's data.

I'm a strong advocate for option 1, as I think it is far better for the DAL to manage that sort of abstraction, because that is its job. This allows the business object to focus entirely on business rules and not messy things like data source mapping.

Chicagoan2016 commented 7 years ago

Thank you Fuji, thank you Rocky, I will go ahead and generate DTOs that corresponds to my business classes but with simple properties.