I would like to know what the best practice for populating a business object hierarchy (parent/child/grandchild) structure is from a single database call.
I can think of a couple ways to accomplish it off the top of my head such as:
left-joining all the relations in my sql statement then use looping and logic to fill the business objects
or
use several select statements and 1 datareader and use its NextResult() method to iterate through each result set and fill the corresponding BO’s
Just wondering what the best practice for this is
I am using DAAB and c# for my DAL
Thanks!
There is no universal recipe. It depends on database schema, database size and number of records your application reads in typical scenario. You have two processes here:
Fetching data from database is several magnitudes slower than creating objects in memory. Best way would be to construct select statements for fastest data access.
Queries can be constructed in three ways:
You should decide which solution is acceptable. Some key points to consider: