J
Jon Sequeira
I'm looking for a streamlined way to select data from multiple related SQL
tables into a typed DataSet with constraints that require all linked rows to
be retrieved.
There are a couple of questions here.
1) Can multiple tables be returned by one DataAdapter.Fill operation? (I
guess this supposes there's a way to return multiple tables with one
SqlCommand.)
Here's a simple example of what I'd like to do. Suppose two tables, an order
table and an order_item table:
order
-----
id
order_date
etc
order_item
----------
product_id
order_id [a foreign key to order.id]
etc
I'd like to create a query builder that will know to fetch the appropriate
rows from order_item when a query is made against order. For example, say
the query
SELECT * FROM [order] WHERE [order].customer_name LIKE '%Jon%'
returns orders with ids 1, 6, and 345. I'd like to automatically generate a
second query that retrieves the related rows from order_item. I've written
this in the business layer, but I'd like the multiple queries to execute in
one stored procedure if possible, to save database round trips.
And, ideally, this effect would cascade to other tables related to
order_item and so on.
Any insights are much appreciated.
Thanks.
Jon
tables into a typed DataSet with constraints that require all linked rows to
be retrieved.
There are a couple of questions here.
1) Can multiple tables be returned by one DataAdapter.Fill operation? (I
guess this supposes there's a way to return multiple tables with one
SqlCommand.)
Here's a simple example of what I'd like to do. Suppose two tables, an order
table and an order_item table:
order
-----
id
order_date
etc
order_item
----------
product_id
order_id [a foreign key to order.id]
etc
I'd like to create a query builder that will know to fetch the appropriate
rows from order_item when a query is made against order. For example, say
the query
SELECT * FROM [order] WHERE [order].customer_name LIKE '%Jon%'
returns orders with ids 1, 6, and 345. I'd like to automatically generate a
second query that retrieves the related rows from order_item. I've written
this in the business layer, but I'd like the multiple queries to execute in
one stored procedure if possible, to save database round trips.
And, ideally, this effect would cascade to other tables related to
order_item and so on.
Any insights are much appreciated.
Thanks.
Jon