Database Reference
In-Depth Information
relationships as independent relationships and not as separate entities. Thus it is only showing the entries as two:
one of these entries is for the speaker and the other is for the talk. No entry is made for the many-to-many association
entry, because Change Tracker does not return the state of independent relationships. The second thing that Entity
Framework did was to fix up the talk's speaker collection.
When we call SaveChanges() , Entity Framework raises the overridden SaveChanges event. Inside this event,
we update the CreateDate and RevisedDate properties. Before the SaveChanges() method is called, Entity Framework
calls DetectChanges() to find any changes that occurred before. In Listing 8-10, we override the SaveChanges() method.
The DetectChanges() method relies on a snapshot base comparison of the original and current values for each
property on each entity. This process determines what has changed in the object graph. For large object graphs,
this comparison process may be time consuming.
8-8. Testing Domain Objects
Problem
You want to create unit tests for the business rules you have defined for your entities.
This type of recipe is often used when unit testing of specific data access functionality has to be performed.
Solution
For this solution, you'll use the POCO template to generate the classes for your entities. Using the POCO template will
reduce the amount of code you need to write, and it will make the solution a more clear. Of course, you will use the
remaining steps in this solution with your handcrafted POCO classes.
Suppose you have a model like the one shown in Figure 8-9 .
Figure 8-9. A model of reservations, schedules, and trains
 
Search WWH ::




Custom Search