I am trying to find a clean and effective solution to this problem, but somehow stuck.
General information:
-ASP.Net C # Application (.Net 3.5)
-MS-SQL Server 2005
Here's what the data looks like:
Category → Template → Instance
A category can contain several templates.
A template can contain multiple instances.
There is a class for each of these 3 and the corresponding database table with a large number of columns.
I want to load a full category from a database into an object of a class class in C #, including all associated template and instance objects.
I have two options:
1) Join all 3 tables and immediately read all the data.
Surface : much faster on the database side, all information in one query.
Downside . I am passing a lot of redundant data because each line has the same category and template data for each instance.
Example (simplified):
CategoryID | CategoryName | TemplateID | TemplateName | InstanceID | InstanceName
1 | FirstCategory | 1 | FirstTemplate | 1 | FirstInstance
1 | FirstCategory | 1 | FirstTemplate | 2 | SecondInstance
1 | FirstCategory | 1 | FirstTemplate | 3 | ThirdInstance
1 | FirstCategory | 1 | SecondTemplate | 4 | FourthInstance
2) I query each table myself, first collect the category data, then the associated template data with the category identifier, etc.
Surface . An intuitive approach that is easier to handle on the part of the code does not extract unnecessary data.
Downside . A few server requests may be slower.
? ?
1, , , "". .
1, ?
?
- ?
! .