I want to create 3 tables based on 3 entities using code-first and fluent API. I am using Entity Framework version 6. The join table needs a 3-column primary key and additional columns.
My question: how can I use code-first with C# Fluent API to create/map the 3-column primary key for the PatientTreatment
table? Thank you.
Details of the 3-column primary key for the join table { PatentId, TreatmentId , TreatmentDate }. The values of PatentId
and TreatmentId
are fetched from the other 2 entities (tables) while the value of TreatmentDate
is entered manually (e.g. C# code or T-SQL script like calling getdate()
function).
Details of the 3 entities:
public class Patient {
public long PatentId {get; set;} // database created using Identity
...
}
public class Treatment {
public long TreatmentId {get; set;} // database created using Identity
...
}
And the join table (entity)
public class PatientTreatment
{
public long PatentId {get; set;} // part of the primary key from the Patient entity
public long TreatmentId {get; set;} // part of the primary key from the Treatment entity
public DateTime TreatmentDate {get; set;} // part of the primary key but its value is from C# code or from T-SQL script, not from other entity (table)
// other fields ...
}