S
Stephen Muecke
VB.NET/SQL Server
Using datareader to create objects and populate collections (no datasets
involved)
Part of my object model looks like this (with corresponding tables in the
database with PrimaryKey/ForeignKey relationships)
Organisation
contains Projects
contains Contacts
contains Allowances
contains Adjustments
contains Adjustment Costs
Which of the following will provide better performance in terms of
downloading data?
Read all Projects belonging to the Organisation, then loop through each
Project and read all Contracts belonging to the Project,then loop through
each Contract and read all allowances belonging to the Contract etc.
OR
Amend my stored procedures to include multiple joins (up to 6 levels deep)
so that I read all Projects belong to the Organisation, then read all
Contracts belonging to the Organisation, then read all Allowance belonging
to the Organisation etc.
The first method means I can create the correct heirarchy as data is read
but involves many more calls to server and corresponding open/closing of the
reader.
The second method involves less (but more complex) calls. In addition, I
would need to create a temporary hashtable of each collection in order to
find out where objects lower down the model belong
Stephen
Using datareader to create objects and populate collections (no datasets
involved)
Part of my object model looks like this (with corresponding tables in the
database with PrimaryKey/ForeignKey relationships)
Organisation
contains Projects
contains Contacts
contains Allowances
contains Adjustments
contains Adjustment Costs
Which of the following will provide better performance in terms of
downloading data?
Read all Projects belonging to the Organisation, then loop through each
Project and read all Contracts belonging to the Project,then loop through
each Contract and read all allowances belonging to the Contract etc.
OR
Amend my stored procedures to include multiple joins (up to 6 levels deep)
so that I read all Projects belong to the Organisation, then read all
Contracts belonging to the Organisation, then read all Allowance belonging
to the Organisation etc.
The first method means I can create the correct heirarchy as data is read
but involves many more calls to server and corresponding open/closing of the
reader.
The second method involves less (but more complex) calls. In addition, I
would need to create a temporary hashtable of each collection in order to
find out where objects lower down the model belong
Stephen