This course will be retired on June 1, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
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.
Follow Along
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
Code
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
Additional Learning
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up