FirstName);
Executing queries locally has two benefits. First, once the set of data is loaded locally, it can be queried
as often as necessary without the need of going to the database again for each subsequent query. Second,
the entire set can be serialized.
Deferred versus Immediate Data Loading
Earlier in the chapter you learned that when querying across relationships, only the objects you specifically
ask for are returned, and related objects are retrieved later, when you specifically request that
information. For example, the following code loads the necessary employee object, and then, based on
252
Chapter 12: Advanced Query Concepts
the results of the query, sends the Contacts object off for execution. This is known as deferred data
loading.
AdventureWorks db = new AdventureWorks("Integrated Security=sspi");
IQueryable
empQuery =
from emp in db.Employees
where emp.ManagerID == 21
select emp;
foreach (Employee empObj in empQuery)
{
if (empObj.ContactID > 1100)
{
GiveBigPhatRaise(empObj.Contacts);
}
}
Immediate loading, on the other hand, retrieves both sets of data together.
Pages:
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407