Database Reference
In-Depth Information
Figure 5-13. Accessing the Local collection never generates a SQL query
Right now, the result is zero, as we have not yet executed a query for Clubs against the context object. Keep in
mind that the Local collection is automatically kept in sync with the underlying context object.
Next we query the context object for the first two Club entities in the data store and loop through them, rendering
the name and location of each, as shown in Figure 5-14 .
Figure 5-14. Querying the context object always generates a SQL query
Immediately after, we loop through the corresponding Local collection for Clubs and get the same result.
Remember that the results are identical, as the Local collection automatically synchronizes with the DbContext. When
new entities are fetched into the context, the Local collection is automatically updated with those entities. However,
note in Figure 5-15 that no SQL query was generated when accessing the Local collection.
Figure 5-15. Accessing the Local collection never generates a SQL query
To demonstrate further the Local Property default behavior, we fetch a third Club entity by querying from the
underlying context object. Once again, as we loop through both the context and Local collection, we get the same
result. Note in Figure 5-16 that querying the context object always generates a SQL statement and that querying the
Local collection does not, as shown in Figure 5-17 .
Figure 5-16. Querying the context object always generates a SQL query
 
Search WWH ::




Custom Search