Task 1: Connect a Database to an ASP.NET App

In the Program.cs file

  1. Start MySQL Workbench and create a new schema named TechJobs.
    1. In the administration tab, create a new user, TechJobs with the same settings described in the CodingEvents tutorial and set the password to TechJobs.
  2. Make sure that the TechJobs6Persistent project has all of its necessary dependencies.
    1. Pomelo.EntityFrameworkCore.MySql
    2. Microsoft.EntityFrameworkCore.Design
    3. Microsoft.EntityFrameworkCore.Relational
  3. Read through the code that is currently in JobDbContext to get an idea of what the database will look like in terms of tables.
  4. You will need to add the services required to create your database connection in Program.cs, including both the connectionString and the serverVersion.
  5. Run a new migration and update the database.
Tip

You can double-check your setup against what you’ve already done for your CodingEvents repo. You can copy these property assignments from your CodingEvents repo, only needing to change the database address and username/password values.

Test It with SQL

If you correctly connect to your database, you should have tables for Jobs, Employers, and Skills.

  1. In your MySQL workbench, open a new query tab to check your database connection.
    1. Do you see tables?
    2. Do your tables have columns?

SQL TASK:

In queries.sql under “Task 1”, list the columns and their data types in the Jobs table. Write this answer as a comment.

Progress Check

Project Check: You should be able to connect to your MySQL database and perform an initial migration. Your project should open a localhost browser window with a header that reads: “Tech Jobs & Persistent Data” with a message below that there are no jobs yet.

If you click through the application, you will see that not every page is functional. You will be addressing this as you work through the next tasks below.

Database check: You should have empty tables.

You are ready for Task 2 .