SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 396 | Next

Scott Klein

"Professional LINQ"

This is especially useful if
you need access to both sets of data immediately. To illustrate this, the following example uses the
SalesOrderHeader and SalesOrderDetail tables from the AdventureWorks database, and assumes
that mappings to each table and the associated [Association] and EntitySet references have been
defined.
The example queries the SalesOrderHeader table for all orders that were made by SalesPersonID 275,
and returns one set. The first foreach loop loops through that result set, while the inner foreach loops
through the corresponding order details, thus returning the second set of data. Remember that the results
are not returned until the iteration over the query variable takes place. Therefore, as each foreach loop
is iterated over, both sets of data are returned.
IQueryable sohQuery =
from soh in db.SalesOrdersHeader
where soh.SalesPersonID == 275
select soh;
foreach (SalesOrdersHeader sohObj in sohQuery)
{
foreach (SalesOrdersDetail sodObj in sohObj.SalesOrdersHeader)
{
//Do something
}
}
Obviously, there are latency hits when you return large amounts of data, so you will want to use immediate
loading when you need access to both sets of data right out of the gate.


Pages:
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6