Database Reference
In-Depth Information
Following is the output of the code in Listing 3-37:
Orders shipped to the account's city, state...
Order 31 for $223.09
Order 32 for $99.29
How It Works
To solve this problem, you could find all the accounts and then go through each Orders collection and find the orders
that are in the same city and state as the account. For a small number of accounts, this may be a reasonable solution.
But in general, it is best to push this sort of processing into the store layer where it can be handled much more
efficiently.
Out-of-the-gate, both Account and Order are joined by the AccountId property. However, in this solution, we
form an explicit join by creating an anonymous type on each side of the equals clause for each of the entities. The
anonymous construct is required when we join entities on more than one property. We need to make sure that both
anonymous types are the same. They must have the same properties in the same order. Here, we are explicitly creating
an inner-join relationship between the two tables on the database, meaning that orders to other cities and states
would not be included due to the join condition.
 
Search WWH ::




Custom Search