Now that we’ve defined our two POCO model classes, let’s
create a class that we can use to handle the retrieval/persistence of Dinner
and RSVP instances from a database.
We’ll name this class “NerdDinners”. It derives from the
DbContext base class, and publishes two public properties – one that exposes
our Dinner objects, and one that exposes our RSVP objects:
The DbContext and DbSet classes used above are provided as
part of the EF4 Code-First library. You’ll need to add a reference to the
System.Data.Entity.CTP assembly that is installed into the \Program
Files\Microsoft ADO.NET Entity Framework Feature CTP4\Binaries directory to
reference these classes. You’ll also want to add a “using
System.Data.Entity” namespace statement at the top of your “NerdDinners” class
file.
That is all the code we need to write
The above three classes contain all of the code necessary to
implement a basic model and data persistence layer for our NerdDinner
application. We do not need to configure any additional database schema
mapping information, nor run any tools, nor edit any XML files, nor use any
designers in order to start using our classes to retrieve, update, and save
data into a database.