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-1. The simple model that we’ll use in the following examples<br />

Building POCOs by Hand Versus<br />

Generating with a T4 Template<br />

The POCO and related classes created in this chapter are built manually. If you<br />

are starting with a model, it makes much more sense to use a T4 template to<br />

generate the POCO classes from the model. However, in this chapter, the goal is<br />

to provide you with a good understanding of the classes; so we will begin by<br />

building them by hand. Once you know what goes into these classes, you will<br />

have the knowledge you need to properly define a template to do this task for<br />

you. As noted toward the end of this chapter, Microsoft provides a predefined<br />

POCO T4 template and you will also find many that have been created by<br />

developers in the <strong>com</strong>munity, provided through their blogs and other resources.<br />

Example 13-1 displays the code listing for the Contact class. Notice that it uses autoimplemented<br />

properties which don’t require a backing variable to retain their values.<br />

When C# 3.0 and VB9 were released along with Visual Studio 2008,<br />

only C# had auto-implemented properties. They were introduced into<br />

Visual Basic 10 which was released along with Visual Studio 2010.<br />

using System;<br />

using System.Collections.Generic;<br />

using System.Linq;<br />

Example 13-1. A simple Contact class

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

Saved successfully!

Ooh no, something went wrong!