class Event{
int? EventID{get;set;}
int? FirstParticipantID{get;set;}
Participant FirstParticipant{get;set;}
int? SecondParticipantID{get;set;}
Participant SecondParticipant{get;set;}
int? CreatedByID{get;set;}
User CreatedBy{get;set;}
}
class Participant{
int? ParticipantID{get;set;}
List<Event> Events{get;set;}
int? CreatedByID{get;set;}
User CreatedBy{get;set;}
}
protected override void OnModelCreating(DbModelBuilder modelBuilder){
modelBuilder.Entity<Event>().HasRequired(m => m.FirstParticipant).WithMany(m => m.Events).HasForeignKey(m => m.FirstParticipantID);
modelBuilder.Entity<Event>().HasRequired(m => m.SecondParticipant).WithMany(m => m.Events).HasForeignKey(m => m.SecondParticipantID);
modelBuilder.Entity<Event>().HasRequired(m => m.CreatedBy);
modelBuilder.Entity<Participant>().HasRequired(m => m.CreatedBy);
}
It seems very clear to me, but EF (and sql) keeps complaining, no matter what moves I make to the hasmanny/hasrequired stuff. I can't even find google help cause I don't know the name of what I'm trying to implement (double one to one???!!!)
The idea is that an Event must have 2 not null Participants (first & second only, not many) and that each Participant may have many Events
Thanks