EF : Alternative Way of Handling Many-To-Many Relationships

Handling many-to-many relationships using Entity Framework with Code-First approach has been a little challanging for me in the past. I do not recall properly but most was due to having CRUD operations on the child collection objects. Also, due to EF abstraction in the Core-First approach, handling data directly in the database in a traditional way becomes a bit difficult.

Follwing is the usual way to model many-to-many relations with Code-First approach in EF:

public class Employee
{
    public int Id { get; set; }
    public string Name { get; set; }
    public virtual ICollection<Qualification> Qualifications { get; set; }
}

public class Qualification
{
    public int Id { get; set; }
    public string Title { get; set; }
    public virtual ICollection<Employee> Employees { get; set; }
}

Now, operations on these might look like following:

//Adding a qualification to an employee
var emp = await db.Employees.SingleOrDefaultAsync(p => p.Id == 4);
var qual = await db.Qualifications.SingleOrDefaultAsync(p => p.Id == 4);
emp.Qualifications.Add(qual);

Assuming, I am getting the entities Ids from the client, I need to pull them everytime and make changes accordingly. This is abstraction done well by EF.

But if I want more direct access I can break the relationship into 1-to-many:

public class Employee
{
    public int Id { get; set; }
    public string Name { get; set; }
    public virtual ICollection<EmployeesQualifications> EmployeeQualifications { get; set; }
}

public class EmployeesQualifications
{
    public int Id { get; set; }
    public int EmployeeId { get; set; }
    public int QualificationId { get; set; }
}

public class Qualification
{
    public int Id { get; set; }
    public string Title { get; set; }
    public virtual ICollection<EmployeesQualifications> QualificationEmployees { get; set; }
}

And now I can perform operations like following given I am getting only the entities' Ids:

//Adding a qualification to an employee
db.EmployeesQualifications.Add(new EmployeesQualifications
{
    EmployeeId = 4,
    QualificationId = 4
});

By using this approach, I have more direct access to the tables and I reduce the code I need to bring in related entities into the context to perfrom an operation. Its nothing ground breaking but I think its worth putting it out there for people to know and for me to remind myself in the future.