After the first two videos for C# Entity Framework (Video 1 and Video 2) I have decided to make a small one for the Code First approach.
I have used the materials of SoftUni here, mainly concentrating on problem 3. Then I simply played a bit with the migrations in C# to see what they can do. In general – they do their job. 🙂
The code for from the video is mainly here. The MSDN is here. To summarize the MSDN, these are probably the most important commands:
- Enable-Migrations *run in Package Manager Console to start the migration party
- Add-Migration *scaffolds the next migration based on changes you have made to your model since the last migration was created
- Update-Database * applies any pending migrations to the database
- Update-Database –TargetMigration: AddBlogUrl
- Update-Database –TargetMigration: $InitialDatabase *rolls back to empty DB
- Update-Database -Script -SourceMigration: $InitialDatabase -TargetMigration: AddPostAbstract *gets SQL Script
I hope you have enjoyed it! 🙂