O'Reilly logo

Programming Entity Framework: Code First by Rowan Miller, Julia Lerman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 2. Your First Look at Code First

If you’ve worked with either the first or second edition of Programming Entity Framework, you may recall the business that was the focus of the book sample—Break Away Geek Adventures, also known as BAGA. BAGA coordinates much-needed adventure travel for geeks like us. But it’s been a few years, and the business is growing again, so it’s time for some new apps. And since BAGA caters to software geeks, they can’t resist an excuse to try out a new technology such as EF’s Code First.

In this chapter, we’ll start with a small example to witness some of Code First’s default behavior and then add to this example bit by bit to see how each thing we do impacts this behavior.

We’ll begin with a small slice of BAGA’s business domain: the Destinations of our trips and the Lodgings where our geek clients stay on these trips.

The beauty of Code First is that the code we use to define our domain classes is the same code that is used to describe the data model on which Entity Framework relies. And that’s just where we will start—with the code, shown in Example 2-1, which describes the Destination and Lodging classes. For these early examples, we’ll keep the classes very simple; they’ll contain some auto-implemented properties and no further logic.

Example 2-1. The domain model
public class Destination
{
  public int DestinationId { get; set; }
  public string Name { get; set; }
  public string Country { get; set; }
  public string Description { get; set; }
  public byte ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required