concept Author in category entity framework

appears as: Author
Entity Framework Core in Action

This is an excerpt from Manning's book Entity Framework Core in Action.

The Books table name comes from the DbSet<Book> property name of Books in the application’s DbContext, which I show in figure 1.5. The Author table name doesn’t have a DbSet<T> property in the application’s DbContext, so the table defaults to the class name, Author. Section 6.10.1 covers these configuration rules in more detail.

Listing 1.1 shows the other class you’ll be using: Author. This has the same structure as the Book class in figure 1.4, with a primary key that follows the EF Core naming conventions of <ClassName>Id (see section 6.3.15). The Book class has a property called AuthorId, which EF Core knows is a foreign key because it has the same name as the Author primary key.

Listing 1.1 The Author class from MyFirstEfCoreApp
public class Author
{
    public int AuthorId { get; set; }    #1  
    public string Name { get; set; }
    public string WebUrl { get; set; }
}

#1   Holds the primary key of the Author row in the DB. Note that the foreign key in the Book class has the same name.

Figure 9.7 An external system that asks for a specific book and gets the JSON containing the book and all its relationships. When the external system wants to update the authors’ names, it sends back all the original JSON, with the changed names, but tells your application that it needs only the authors’ names changed. Your application uses EF Core’s ChangeTracker.TrackGraph method to set all the classes to state Unchanged, but sets the IsModified flag on the Name property in the Author entity class.

c09_07.png