Here's your problem:-
[ForeignKey("Clinician_Client")]
public int Clinician_ClientId { get; set; }
public virtual ICollection<Clinician_Client> Clinician_Client { get; set; }
What do you suppose the value of Clinician_ClientId
should be?
It can't be the Clinician_ClientId
of the related Clinician_Client
object, because you intend each Clinician
(and each Client
) to be associated with many Clinician_Client objects.
It looks like the model builder is looking at the type ICollection<Clinician_Client>
for a property to match with Clinician_ClientId (e.g. "Id"). It doesn't have one, because it's an ICollection<Clinician_Client>
, not a Clinician_Client
.
As an aside, you might want to consider giving your Clinician_Client object a better name to describe its payload. Perhaps "CarePeriod"?
Try something more like the following:-
public class Clinician
{
public int ClinicianId { get; set; }
public virtual ICollection<CarePeriod> CarePeriods { get; set; }
...
}
public class Client
{
public int ClientId { get; set; }
public virtual ICollection<CarePeriod> CarePeriods { get; set }
...
}
public class CarePeriod
{
public int CarePeriodId { get; set; }
public int ClinicianId { get; set; }
public virtual Clinician Clinician { get; set; }
public int ClientId { get; set; }
public virtual Client Client { get; set; }
...
}
You shouldn't need to mess around with [Key]
attributes, etc. The default conventions should have you covered, unless I'm missing something about your connector.