DBFirst one to one or zero
I have One Patient to One or No MedicalCard associated with him
EF Generated the following code:
Why did it create Collections? What's the use of them? I have id and single entity navigation property, but why the collections?
EF Generated the following code:
public Patient(){
{
Appointments = new HashSet<Appointment>();
MedicalCards = new HashSet<MedicalCard>();
}
public int Id { get; set; }
public string? Lastname { get; set; }
public string? Firstname { get; set; }
public string? Middlename { get; set; }
public string? Phone { get; set; }
public string? Address { get; set; }
public bool? Gender { get; set; }
public int? Medcard { get; set; }
public virtual MedicalCard? MedcardNavigation { get; set; }
public virtual ICollection<Appointment> Appointments { get; set; }
public virtual ICollection<MedicalCard> MedicalCards { get; set; }
public partial class MedicalCard
{
public MedicalCard()
{
MedicalReports = new HashSet<MedicalReport>();
Patients = new HashSet<Patient>();
}
public int Id { get; set; }
public int Patient { get; set; }
public DateTime? Issued { get; set; }
public virtual Patient PatientNavigation { get; set; } = null!;
public virtual ICollection<MedicalReport> MedicalReports { get; set; }
public virtual ICollection<Patient> Patients { get; set; }
}public Patient(){
{
Appointments = new HashSet<Appointment>();
MedicalCards = new HashSet<MedicalCard>();
}
public int Id { get; set; }
public string? Lastname { get; set; }
public string? Firstname { get; set; }
public string? Middlename { get; set; }
public string? Phone { get; set; }
public string? Address { get; set; }
public bool? Gender { get; set; }
public int? Medcard { get; set; }
public virtual MedicalCard? MedcardNavigation { get; set; }
public virtual ICollection<Appointment> Appointments { get; set; }
public virtual ICollection<MedicalCard> MedicalCards { get; set; }
public partial class MedicalCard
{
public MedicalCard()
{
MedicalReports = new HashSet<MedicalReport>();
Patients = new HashSet<Patient>();
}
public int Id { get; set; }
public int Patient { get; set; }
public DateTime? Issued { get; set; }
public virtual Patient PatientNavigation { get; set; } = null!;
public virtual ICollection<MedicalReport> MedicalReports { get; set; }
public virtual ICollection<Patient> Patients { get; set; }
}Why did it create Collections? What's the use of them? I have id and single entity navigation property, but why the collections?
