Hi to all. What are the best (cleaner, less resource expensive) ways to pass one-to-many relationships from a db server to a client?
Imagine that I have a Author table and a Book table. I want to to retrieve all the authors whose name starts with "a" and all the books they've written. Then, client-side, generate an array of objects "Author" whose "Books" field is an array of objects "Books".
Two poor man solutions that come to my mind are:
- Retrieve all the authors, cycle through them on the client and execute an additional query to get all the books
- "SELECT a.* FROM author a, book b WHERE a.name like 'A%' and b.author_id = a.id"
The first solution is really database-side intensive (if i have 1000 authors, i have to execute 1001 queries).
The second requires some intensive work client-side, as the program would parse the result as it has the data common to Author repeated on each row.
Another solution would be to return multiple record sets from a stored procedure. I've never handled multiple record sets and I'm not sure that all the languages / adaptor classes support them.
Of course the situation can get worse if any author can have books and essays and every book can have sample pages and so on.
Any idea? Thanks
EDIT: I'm using .net, so ado's datarelations are an option. Are they supported my oracle and mysql?