public class PatientDbContext : DbContext
{
public DbSet<Patient> Patients { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// Set the file location for the patient database
optionsBuilder.UseSqlite("Data Source=patients.db");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Patient>()
.HasMany(p => p.Appointments)
.WithOne(a => a.Patient)
.HasForeignKey(a => a.PatientId)
.OnDelete(DeleteBehavior.Cascade);
}
}
public class Patient
{
public int Id { get; set; } //Unique ID
public string FirstName { get; set; }
public string Surname { get; set; }
public DateTime DateOfBirth { get; set; }
public string ContactDetail { get; set; }
public string NHSNumber { get; set; }
public string HospitalNumber { get; set; }
public string HospitalRecords { get; set; }
public ICollection <Appointment> Appointments { get; set; }
} // class patients
} //namespace