In my blog post last week I walked through building a simple
“NerdDinner” application from scratch, and demonstrated the productivity gains
EF “code first” delivers when working with data.

Below are the two model classes we created to represent data
within the application. They are “plain old CLR objects” (aka “POCO”)
that only expose standard .NET data types:

We then created a “NerdDinners” class to help map these
classes to/from a database. “NerdDinners” derives from the DbContext
class provided by the EF “code first” library and exposes two public
properties:

We used the default EF4 “code first” conventions to enable
database persistence. This means that the “Dinners” and “RSVPs” properties
on our “NerdDinners” class map to tables with the same names within our
database. Each property on our “Dinner” and “RSVP” model classes in turn
map to columns within the “Dinners” and “RSVPs” tables.
Below is the database schema definition for the “Dinners”
table within our database:

Below is the database schema definition for the “RSVPs”
table within our database:

We did not have to configure anything in order to get this
database persistence mapping with EF4 “code first” – this occurs by default
simply by writing the above three classes. No extra configuration is
required.