Database Reference
In-Depth Information
Following is the output of the code in Listing 13-26:
Customer: Robin Rosen in Raytown
Card: 41949494338899 expires on 12/1/2010
Transaction: $29.95
Customer: Bill Meyers in Raytown
Card: 41238389484448 expires on 12/1/2013
Transaction: $83.39
How It Works
The Include() method is a powerful and usually efficient way to eagerly load related entities. However, Include()
does have some performance drawbacks. Although using Include() results in just one round trip to the database
in place of the three shown in Listing 13-26, the single query is quite complex and, in some cases, may not perform
as well as three much simpler queries. Additionally, the result set from this single, more complex query contains
duplicate columns that increase the amount of data sent over the wire if the database server and the application are
on separate machines. As a rule, the more Include s contained in your query, the higher the performance penalty.
On the flip side, not using an Include() method and iterating over a large number of Customers can generate an
excessive number of small queries, resulting in a large performance hit as well. Chapter 5 discusses the trade-offs and
alternate approaches in detail.
13-10. Generating Proxies Explicitly
Problem
You have POCO entities that use dynamic proxies. When you execute a query, you do not want to incur the cost of
Entity Framework lazily creating the proxies.
Solution
Suppose that you have a model like the one shown in Figure 13-15 .
Figure 13-15. A model for CDs and music titles
 
 
Search WWH ::




Custom Search