Let’s now look at another common scenario – one where we
want to map a model class to a database schema whose table and column names are
different than the classes and properties we want to map them to.
For example, let’s assume our “tblDinners” database table
contains columns that are prefixed with “col” – and whose names are also all
different than our Dinner class:

We still want to map our clean “Dinners” model class to this
“tblDinners” table – and do so without having to decorate it with any data
persistence attributes:

We can achieve this custom persistence by updating our
“OnModelCreating” method to have a slightly richer mapping rule like so:

The above code uses the same .MapSingleType() and .ToTable()
fluent method calls that we used in the previous scenario. The difference
is that we are also now specifying some additional column mapping rules to the
MapSingleType() method. We are doing this by passing an anonymous object
that associates our table column names with the properties on our Dinner
class.
The dinner parameter we are specifying with the lambda
expression is strongly-typed – which means you get intellisense and
compile-time checking for the “dinner.” properties within the VS code
editor. You also get refactoring support within Visual Studio – which
means that anytime you rename one of the properties on the Dinner class - you
can use Visual Studio’s refactoring support to automatically update your mapping
rules within the above context menu (no manual code steps required).