ConsumerNM is a NM/bridge table/entity.
Its a 1:N relation to Events table.
When I do an insert I get the question title exception.
What do I have to change to make it work?
DO I have to create 2 foreign keys each one pointing to the other ConsumerNM_Key?
public class ConsumerNM
{
public ConsumerNM()
{
Events = new HashSet<Event>();
}
[Key]
[Column(Order = 0)]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int FK_LEADMETA { get; set; }
[Key]
[Column(Order = 1)]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int FK_LEADCONSUMER { get; set; }
public virtual ICollection<Event> Events { get; set; }
}
public class Event
{
[Key]
public int Id { get; set; }
public DateTime EventDate { get; set; }
public virtual ConsumerNM Consumer { get; set; }
[ForeignKey("Consumer")]
public int FK_Consumer { get; set; }
}
ConsumerNMorEventare incorrect. You have two options:First Option:
Eventremains unchanged.Second Option:
ConsumerNMremains unchanged.