I have a Web Service one of whose methods returns a list of items, each of which possesses another list of items:
<TopLevelItems>
<TopLevelItem field1="a" field2="b" ...>
<LowLevelItem fieldA="1" fieldB="2" .../>
<LowLevelItem fieldA="3" fieldB="4" .../>
</TopLevelItem>
</TopLevelItems>
These lists are retrieved from a SQL Server database using simple queries (both TopLevelItem
and LowLevelItem
correspond to related tables in the database).
Until now, to retrieve all this data, I needed two queries: one to retrieve top level items, which was executed once; and another to retrieve low level items, which was executed once per top level item.
However, this seems to be highly inefficient. I would like to define a single stored procedure that performs all the necessary queries and retrieves the result as a hierarchical data structure. Is it possible? If so, how?