Republished with Permission - Original
Article
Last week I blogged about the new Entity Framework 4 “code first”
development option. The EF “code-first” option enables a pretty sweet
code-centric development workflow for working with data. It enables you
to:
Develop without ever having to open a designer or define an
XML mapping file
Define model objects by simply writing “plain old classes”
with no base classes required
Use a “convention over configuration” approach that enables
database persistence without explicitly configuring anything
In last week’s blog post I demonstrated how to use the default
EF4 mapping conventions to enable database persistence. These default
conventions work very well for new applications, and enable you to avoid having
to explicitly configure anything in order to map classes to/from a
database.
In today’s blog post I’m going to discuss how you can
override the default persistence mapping rules, and use whatever custom
database schema you want. This is particularly useful for scenarios
involving existing databases (whose schema is already defined and potentially
can’t be changed) as well as for scenarios where you want your model shape to
be different than how you want to persist it within a relational database.