Database Reference
In-Depth Information
Also, let's say that you have created a trigger, like the one in Listing 12-11, so that the PaidDate column is
populated when the Paid column is set to true. You've also set the TicketId to be an Identity column and CreateDate to
default to the current date. With the trigger in Listing 12-11 and the automatically generated values, only the Amount
and Paid columns are required for an insert.
Listing 12-11. A Trigger That Sets the PaidDate Column When the Paid Bit is Set to true .
CREATE TRIGGER UpdateParkingTicket
ON ParkingTicket
FOR UPDATE
AS
UPDATE ParkingTicket
SET PaidDate = GETDATE()
FROM ParkingTicket
JOIN Inserted i ON
ParkingTicket.TicketId = i.TicketId
WHERE i.Paid = 1
After an insert or an update, you want Entity Framework to populate the entity with the values generated by the
database. To create the model that supports this, do the following:
1.
Right-click the project, and select Add New Item. Add a new ADO.NET Entity Data
Model. Import the ParkingTicket table. The resulting model should look like the one
shown in Figure 12-15 .
Figure 12-15. The model with the ParkingTicket entity
2.
Right-click on each of the scalar properties in the ParkingTicket entity. View the
properties of each. Notice that the StoreGeneratedPattern property is set to Identity for
the TicketId. For TimeStamp, the StoreGeneratedPattern property is set to Computed. The
StoreGeneratedPattern property for CreateDate and PaidDate is not set. Change both the
values to Computed.
 
Search WWH ::




Custom Search