Building a reusable entity data model
Practical applications usually need to work with data in a relational database or another data store. Earlier in this chapter, we defined EF Core models in the same console app project that we used them in.
Now, we will define an entity data model for the Northwind database as a pair of reusable class libraries. One part of the pair will define the entities, like Product
and Customer
. The second part of the pair will define the tables in the database and the default configuration for how to connect to the database, and use the Fluent API to configure additional options for the model. This pair of class libraries will be used in many of the apps and services that you create in subsequent chapters.
Good Practice: You should create a separate class library project for your entity data models. This allows easier sharing between backend web servers and frontend desktop, mobile, and Blazor clients.