It is time to add some data to our table in the created database. We will insert a row, which is sometimes called a record. A record in the People
table consists of values in three columns: PersonId, FirstName, and LastName. These values are going to be based on property values of an instance of the Person
class, which is mapped to the People
table. This is an important concept to remember. When we create entity classes, their purpose is to map to tables. There are some exceptions to this rule, which we will see in later chapters. This table is represented by a collection-based property in our Context
class.
This property's type is DbSet
of Person and its name is People
. Conceptually, you can think of adding objects to that collection to be equivalent to inserting rows into the database's corresponding table. You need to use the Add
method of DbSet
to implement the addition of new data. The DbContext
class has the SaveChanges
method, which is responsible...