Greetings, I have a following question. Suppose where are two tables in the database:
Clients(
id,
name,
address)
Orders(
id,
name,
desc,
datemodified,
client_id)
The second one references the first one, that is each order is assigned to the client. Now suppose I have an .aspx page with a LinqDataSource for Orders table, and a GridView that uses this datasource and displays a table with a following columns:
- Order name.
- Order desc.
- Client name.
- Client address.
As far as I understand, the Linq to SQL is designed in such a way, that by default it does not load any associated entities, it only does it when a child property is requested. So, when a page is loaded, the following situation will occur:
- First query will retrieve the records from the Orders table.
- For each row displayed by GridView an additional query will be performed when one of the client properties is requested.
Therefore, if we have 100 orders, this means will perform 101 queries instead of one (or even maybe 201, if a query will be performed for each client property)? How to avoid this and make LinqDataSource load all the required fields by a single query?
Right now I see the only workaround for this problem - use an SqlDataSource with a join query, that will retrieve all required fields at once.