Answer the question
In order to leave comments, you need to log in
Why does EF6 CodeFirst many-to-many conflict with ForeignKey?
I have two classes like this, ef doesn't want to create a many-to-many table, when I add the Client_Id field, it will add the Class_ID to the Client table, but if I remove the Curator_Id field, then many-to-many is created... What's the problem ?
public class Class
{
public int ID { get; set; }
public Class()
{
this.Members = new HashSet<Client>();
}
public virtual ICollection<Client> Members { get; set; }
[ForeignKey("Client_Id")]
public virtual Client Client { get; set; }
public virtual string Client_Id { get; set; }
}
public class Client
{
public Client()
{
this.Classes = new HashSet<Class>();
}
public string Id {get; set;}
public virtual ICollection<Class> Classes { get; set; }
}
Answer the question
In order to leave comments, you need to log in
It is better to use the Fluent API Relationships between models in the Fluent API
You, as I understand it, want to have both a Client list and another Client list in the "Event" which is the curator. You need to poke it, some things EF cannot do either in one migration, or at all.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question