Task 3: Creating a Many-To-Many Relationship
Using a many-to-many relationship, we can apply jobs to multiple skills, and a skill to multiple jobs. We want to create a table that will track the relationships between both Jobs and Skills. To do this, we need to tell the
Modelbuilder which properties to use.
- In the
OnModelCreatingmethod, we want to create a table called
“JobSkills”. This table will use an
Job. It has many
Jobs. It will use
Entityto create a table named
- Run a new migration and update your database to see your new table.
Test It with SQL
Run your application and make sure you can create a new job with an employer and several skills. You should now also have restored full list and search capabilities.
queries.sql under “Task 3”, write a query to return a list of the skills that are attached to jobs in alphabetical order. If a skill does not have a job listed, it should not be included in the results of this query.
You will need to make use of “is not null”.
Testing: Run the tests found in
Task.Tests. These should all pass unless your database connections have been set incorrectly.
You will need to uncomment the code for the unit tests. Look for
TODO statements in lines 1 and 304 in the
Build: You should have a working website that allows you to make a job, employer, and skill and connect them. You should be able to see the connections in an the
Database: and see data in MySQL database. You should see data in your
JobSkills table. It should be a pairing of Job and Skill Ids.
How to Submit
To turn in your assignment and get credit, follow the submission instructions .
You have successfully completed Graded Assignment 4 in C#!