A primary key is a column or set of columns whose values uniquely identify rows. In an EF Core code-first model, an entity property named Id becomes the key by convention. section 5.2
EF Core key configuration follows two practical paths:
- Use an Id property, which EF Core recognizes as the primary key when building the table. section 5.2
- Mark another property, such as ISBN, with the [Key] attribute when it should identify rows instead. section 5.2
- Include the entity in a DbContext so EF Core relates the class to a database table and generates the key column. section 5.2
Book entity
A Book class with an int Id property maps to a Books table whose Id column is the primary key. Adding several books and ordering by b.Id demonstrates using the key to distinguish and retrieve rows. section 5.2
Listing 5.2 Book class to represent a book in the Manning catalog
namespace ManningBooks;
public class Book
{
public int Id { get; set; } #1
public string Title { get; set; }
}
Inspect the Book entity declaration and its convention-based Id key. section 5.2




















