Basically, you just need:
public class EmployeeRegion
{
[Key, Column(Order = 1)]
public int EmployeeId { get; set; }
public virtual Employee Employee { get; set; }
[Key, Column(Order = 2)]
public int RegionId { get; set; }
public virtual Region Region { get; set; }
}
In other words, the part you're missing is [Key, Column(Order = N)]. This makes the ids an actual composite key, which out of the box won't allow duplicates.
However, all this does is make the API more difficult for working with this M2M relationship. If the only data in the table is the keys and there's no payload of additional data needed for the relationship, then you should get rid of this entity and simply let EF handle the relationship:
public class Employee
{
...
public virtual ICollection<Region> Regions { get; set; }
}
public class Region
{
...
public virtual ICollection<Employee> Employees { get; set; }
}
Behind the scenes, EF will create a table similar to what you have with EmployeeRegion, but you won't be responsible for managing that, and things like ensuring unique relationships will be baked in. This also buys you a much easier API to work with. For example. To get all the employees for a region, currently, you'd have to do something like:
dbo.EmployeeRegions.Where(m => m.Region.Id == regionId).Select(m => m.Employee)
Whereas, by allowing EF to handle it, you can just do:
region.Employees
EmployeeRegionentity entirely and just let EF handle the relationship implicitly.