Join Richard Goforth for an in-depth discussion in this video Using the exercise files, part of Accessing Existing Databases with Entity Framework Core.
- [Narrator] This course includes exercise files, which you can use to follow along as you progress through the course. If you have access to them, feel free to download them and place them on your desktop, as I've done here. I'm also going to create an empty project folder. We'll be working out of this folder for the remainder of the course. The files are broken up by chapter and video. The Start folder contains the project files that match the beginning of the video, and the Completed folder contains the project as it is at the end of the video.
This way you can check the code you've written matches what I've done. The SQL script that we'll be using to restore the database is here at the root of the exercise files. Ideally, you'll follow along from the beginning of the course, in which case you shouldn't need to open the exercise files for each video. But if you just want to check out a couple of videos starting after the beginning of chapter two you'll need to restore the database as we will in the video connecting the database. Once the database has been restored you can copy the files to your project folder.
I'll hit copy, open the project folder, and paste. I'm going to press Windows + R and type CMD to open a command window, then navigate to the location of the project folder. Now I'll run dotnet restore and dotnet ef database update. This will bring the database into line with the current project. With that you're all set to go. If you've previously restored the database, delete it. In my case I'm going to open Visual Studio and open Sql Server Object Explorer by going to View and going to Sql Server Object Explorer.
Drop down (localdb)\MSSQLLocalDB, databases, click on the HPlusSports database, right click and click delete. Check close existing connections to make sure that nothing holds the database open. Now you can recreate the database, restore it from the SQL script, and start from a clean slate. Now I'll close Visual Studio, close the command video, and delete the files from the project folder. We're ready to get coding. If you're not on a Windows machine in the exercise files you can safely ignore the xproj Visual Studio project file.
You can open and edit the JSON files in your text editor of choice.
- Setting up your project
- Connecting to a legacy database
- Scaffolding an initial model and context
- Improving the model
- Updating properties and indexes
- Adding concurrency tokens and timestamps
- Creating complex relationships
- Working with non-Microsoft databases such as SQLite and PostgreSQL