EF Core uses a combination of conventions, annotation attributes, and Fluent API statements to build an entity model at runtime so that any actions performed on the classes can later be automatically translated into actions performed on the actual database. An entity class represents a row in a table.
The code we will write will use the following conventions:
- The name of a table is assumed to match the name of a
DbSet<T>
property in theDbContext
class, for example,Products
- The names of the columns are assumed to match the names of properties in the class, for example,
ProductID
- The
string
.NET type is assumed to be annvarchar
type in the database - The
int
.NET type is assumed to be anint
type in the database - A property that is named
ID
or the name of the class withID
as the suffix is assumed to be a primary key. If this property is any integer type or theGuid
type, then it is also assumed to beIDENTITY
(automatically assigned...