Task 1: Connect a Database to an ASP.NET App
In the Program.cs
file
- Start MySQL Workbench and create a new schema named
TechJobs
.- In the administration tab, create a new user,
TechJobs
with the same settings described in theCodingEvents
tutorial and set the password toTechJobs
.
- In the administration tab, create a new user,
- Make sure that the
TechJobs6Persistent
project has all of its necessary dependencies.Pomelo.EntityFrameworkCore.MySql
Microsoft.EntityFrameworkCore.Design
Microsoft.EntityFrameworkCore.Relational
- Read through the code that is currently in
JobDbContext
to get an idea of what the database will look like in terms of tables. - You will need to add the services required to create your database connection in
Program.cs
, including both theconnectionString
and theserverVersion
. - Run a new migration and update the database.
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
.
- In your MySQL workbench, open a new query tab to check your database connection.
- Do you see tables?
- 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.
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 .