04.07.2013 Views

Programming Entity Framework - Cdn.oreilly.com

Programming Entity Framework - Cdn.oreilly.com

Programming Entity Framework - Cdn.oreilly.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Figure 13-4. The two templates added by the ADO.NET POCO <strong>Entity</strong><br />

Generator and their generated classes<br />

The POCO template creates fairly simple classes with all of their properties marked as<br />

virtual, forcing them to use the DynamicProxy classes at runtime. Additionally, it adds<br />

code to ensure that any foreign keys stay in sync with their related navigation property.<br />

And finally, there is code in there to maintain two-way relationship fix-ups similar to<br />

what you saw earlier in the chapter, although they use a class called<br />

FixUpCollection which you’ll find in BreakAway.cs.<br />

Example 13-11 shows the <strong>com</strong>plete listing for the generated Payment class. Notice the<br />

code in ReservationID which keeps the Reservation property in sync with the<br />

ReservationID foreign key. Additionally, you can see the fix-up code that adds or<br />

removes the Payment to the Reservation.Payments collection as necessary.<br />

Example 13-11. The Payment POCO class generated using the POCO T4 template<br />

//------------------------------------------------------------------------------<br />

// <br />

// This code was generated from a template.<br />

//<br />

// Changes to this file may cause incorrect behavior and will be lost if<br />

// the code is regenerated.<br />

// <br />

//------------------------------------------------------------------------------<br />

using System;<br />

using System.Collections;<br />

using System.Collections.Generic;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!