Database Reference
In-Depth Information
Following is the output of the code in Listing 12-12:
Ticket: 5
Date: 7/3/2013
Amount: $132.00
Paid: Not Paid
Ticket: 6
Date: 7/3/2013
Amount: $255.00
Paid: Not Paid
Ticket: 5
Date: 7/3/2013
Amount: $132.00
Paid: 3/24/2010
Ticket: 6
Date: 7/3/2013
Amount: $255.00
Paid: 3/24/2010
How It Works
When you set a property's StoreGeneratedPattern to Identity or Computed, Entity Framework knows that the database
will generate the value. Entity Framework will retrieve these columns from the database with a subsequent select
statement.
When the StoreGeneratePattern is set to Identity, Entity Framework retrieves the database-generated value just
once at the time of insert. When the StoreGeneratedPattern is set to Computed, Entity Framework will refresh the
value on each insert and update. In this example, the PaidDate column was set by the trigger (because we set Paid to
true ) on update and Entity Framework acquired this value after the update.
12-12. Validating Entities on Saving Changes
Problem
You want to validate entities before they are saved to the database using an ObjectContext.
Solution
Suppose that you have a model like the one shown in Figure 12-16 .
 
Search WWH ::




Custom Search