concept Data Annotations in category entity framework

This is an excerpt from Manning's book Entity Framework Core in Action.
Figure 6.1 When the application’s DbContext is first used, EF Core sets off a process to configure itself and build a model of the database it’s supposed to access. You can use three approaches to configure EF Core: By Convention, Data Annotations, and Fluent API. Most real applications need a mixture of all three approaches to configure EF Core in exactly the way your application needs.
![]()
6.4 Configuring via Data Annotations
Data Annotations are a specific type of .NET attribute used for validation and database features. These attributes can be applied to an entity class or property and provide configuration information to EF Core. This section introduces where you can find them and how they’re typically applied. The Data Annotation attributes that are relevant to EF Core configuration come from two namespaces.
6.9.1 Configuring a primary key via Data Annotations
Listing 6.7 shows the
BookAuthorlinking entity class with the primary composite key being defined using Data Annotations. Because there’s more than one key, you need to include the[Column(Order = nn)]attribute to define the order that the properties appear in the composite primary key.Listing 6.7 The
BookAuthorentity class using Data Annotations to define the keypublic class BookAuthor { [Key] #1 [Column(Order = 0)] #2 public int BookId { get; set; } [Key] #1 [Column(Order = 1)] #2 public int AuthorId { get; set; } public byte Order { get; set; } //----------------------------- //Relationships public Book Book { get; set; } public Author Author { get; set; } } #1 [Key] attribute tells EF Core that the property is a primary key #2 [Column(Order = nn)] tells EF Core the order in which the keys should appear in the composite key. (The numbers are relative; you could’ve used 100 and 200.)