Modifying Migration Classes12:47 with James Churchill
Let's look at example of a model change that will require us to modify the generated migration in order for it to successfully upgrade and downgrade the database.
To follow along commiting your changes to this course, you'll need to fork the dotnet-ef-migrations repo. Then you can clone, commit, and push your changes to your fork like this:
git clone <your-fork> cd dotnet-ef-migrations git checkout tags/v2.2 -b modifying-migration-classes
Here are the SQL statements to migration average rating data from the ComicBook table to the ComicBookAverageRating table and back again.
insert into ComicBookAverageRating select Id, AverageRating, getdate() from ComicBook where AverageRating is not null update cb set cb.AverageRating = cbar.AverageRating from ComicBook cb cross apply ( select top 1 AverageRating, Date from ComicBookAverageRating where ComicBookId = cb.Id order by Date desc ) as cbar
You need to sign up for Treehouse in order to download course files.Sign up