Chapter 5. Using Conventions and Configurations for Database Mappings

So far you’ve learned about Code First convention and configurations that affect property attributes and those that pertain to relationships between classes. In both of these categories, Code First affected not only the model but the database as well. In this chapter, you’ll learn about convention and configurations that focus on how your classes map to the database without impacting the conceptual model.

You’ll start with simple mappings that allow you to specify the names of database tables, schemas and properties. You’ll learn how to enable multiple classes to map to a common table, or map a single class to multiple tables. Finally, we’ll walk you through a variety of inheritance scenarios.

Mapping Class Name to Database Table and Schema Name

Entity Framework uses its pluralization service to infer database table names based on the class names in the model—Destination becomes Destinations, Person becomes People, etc. Your class naming conventions, however, might not be the same as your table naming conventions. You might hit a word that doesn’t get pluralized properly (such as was the case with PersonPhoto, which became PersonPhotoes in Chapter 4). Or you might be mapping to an existing table with names that don’t happen to align with Code First convention.

Note

Entity Framework’s pluralization service uses pluralization for common English words. There is currently no international pluralization service.

You can ...

Get Programming Entity Framework: Code First now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.