I am trying to use code-first and Data Annotations with EF 6.0 with the following, very simple, model of two classes: basically employees who can be organizers and attendees of an event:
public class Employee
{
[Key]
public Guid Id { get; set; }
public string name { get; set; }
public virtual ICollection<Event> event { get; set; }
}
public class Event
{
[Key]
public Guid Id { get; set; }
public string name { get; set; }
[ForeignKey("organizer")]
public Guid organizerId { get; set; }
public virtual Employee organizer { get; set; }
public virtual ICollection<Employee> atendees { get; set; }
}
When I let EF generate the database from these classes it surprisingly doesn't generate the many-to-many relationship between Employee and Event (so, no EmployeeEvent many-to-many table), rather it generates an event-id foreign key in Employees. (I have no clue why.)
Of course, I can directly create the proper db mapping by using the fluent-APIs, but I was wondering if there is a way to achieve this with data annotations.