Contact
where con.FirstName == "Scott"
orderby con.LastName
select con;
foreach (Contact cont in conQuery)
listBox1.Items.Add(cont.FirstName + " " + cont.LastName);
One of the key benefits of remote execution is that you can take advantage of database table indexes,
which you can??™t use when queries are executed locally. You also have the guarantee that needless data is
not returned.
Local Execution
In those cases where local execution is necessary, you have another option. The Load() method of the
EntitySet retrieves all the related entities into your local cache. In the following example, there is a
relationship between the Contact class and Employee class through the EntitySet. Therefore, when the
contacts are loaded, the corresponding employees are loaded as well.
AdventureWorks db = new AdventureWorks("Integrated Security=sspi");
Contact con = db.Contact.Single(x => x.ContactID == 1146);
con.Employee.Load();
foreach (Employee emp in con.Employee.Where(y => y.ManagerID == 210))
listBox1.Items.Add(emp.ContactID + " " + con.
Pages:
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406