4.1: Run Migration

Now we need to update our database to reflect changes to our User entity and add a new table for Photos.

Add Photo DbSet Properties to DbContext

In the .Data project, open up the EFConnectContext.cs file and add a DbSet property for the Photo class:

public DbSet<User> Users { get; set; }

public DbSet<Photo> Photos { get; set; }        // <---- Added

Run New Migration and Update the Database

Navigate in your terminal to the .Data project and run a migration in your terminal:

dotnet ef migrations add ExtendUser -s "../EFConnect.API/EFConnect.API.csproj"

Then, update the database:

dotnet ef database update -s "../EFConnect.API/EFConnect.API.csproj"

View New Columns and Table

Open up SQL Server Management Studio and verify that your Photo table and User columns were added

DatabaseUpdate

Last updated