[30a465f] | 1 | using FarmatikoData.Models;
|
---|
| 2 | using Microsoft.EntityFrameworkCore;
|
---|
| 3 |
|
---|
| 4 | namespace FarmatikoData
|
---|
| 5 | {
|
---|
| 6 | public class FarmatikoDataContext : DbContext
|
---|
| 7 | {
|
---|
| 8 | public FarmatikoDataContext(DbContextOptions options) : base(options) { }
|
---|
[8e74e2f] | 9 |
|
---|
[30a465f] | 10 |
|
---|
[1454207] | 11 | public virtual DbSet<HealthFacility> HealthFacilities { get; set; }
|
---|
| 12 | public virtual DbSet<HealthcareWorker> HealthcareWorkers { get; set; }
|
---|
[5d02859] | 13 | public virtual DbSet<Pharmacy> Pharmacies { get; set; }
|
---|
| 14 | public virtual DbSet<PharmacyHead> PharmacyHeads { get; set; }
|
---|
[de2baac] | 15 | public virtual DbSet<Pandemic> Pandemics { get; set; }
|
---|
| 16 | public virtual DbSet<Medicine> Medicines { get; set; }
|
---|
[1454207] | 17 | public virtual DbSet<RequestPharmacyHead> PHRequests { get; set; }
|
---|
[d23bf72] | 18 | public virtual DbSet<User> Users { get; set; }
|
---|
[1db5673] | 19 | public virtual DbSet<PharmacyHeadMedicine> PharmacyHeadMedicines { get; set; }
|
---|
[8e74e2f] | 20 |
|
---|
[1db5673] | 21 | protected override void OnModelCreating(ModelBuilder modelBuilder)
|
---|
| 22 | {
|
---|
[8e74e2f] | 23 | modelBuilder.UseSerialColumns();
|
---|
| 24 |
|
---|
[1db5673] | 25 | modelBuilder.Entity<PharmacyHead>()
|
---|
| 26 | .ToTable("PharmacyHeads");
|
---|
| 27 |
|
---|
| 28 | modelBuilder.Entity<Medicine>()
|
---|
| 29 | .ToTable("Medicines");
|
---|
| 30 |
|
---|
[68454c6] | 31 | modelBuilder.Entity<Pharmacy>()
|
---|
| 32 | .ToTable("Pharmacies");
|
---|
| 33 |
|
---|
[8e74e2f] | 34 | modelBuilder.Entity<Medicine>()
|
---|
| 35 | .Property(x => x.Id)
|
---|
| 36 | .HasIdentityOptions(startValue: 1);
|
---|
| 37 |
|
---|
| 38 | modelBuilder.Entity<Pharmacy>()
|
---|
| 39 | .Property(x => x.Id)
|
---|
| 40 | .HasIdentityOptions(startValue: 1);
|
---|
| 41 |
|
---|
| 42 | modelBuilder.Entity<PharmacyHead>()
|
---|
| 43 | .Property(x => x.Id)
|
---|
| 44 | .HasIdentityOptions(startValue: 1);
|
---|
| 45 |
|
---|
| 46 | modelBuilder.Entity<PharmacyHeadMedicine>()
|
---|
| 47 | .Property(x => x.Id)
|
---|
| 48 | .HasIdentityOptions(startValue: 1);
|
---|
| 49 |
|
---|
| 50 | modelBuilder.Entity<RequestPharmacyHead>()
|
---|
| 51 | .Property(x => x.Id)
|
---|
| 52 | .HasIdentityOptions(startValue: 1);
|
---|
| 53 |
|
---|
| 54 | modelBuilder.Entity<User>()
|
---|
| 55 | .Property(x => x.Id)
|
---|
| 56 | .HasIdentityOptions(startValue: 1);
|
---|
| 57 |
|
---|
[1db5673] | 58 | modelBuilder.Entity<PharmacyHeadMedicine>()
|
---|
| 59 | .HasKey(phm => new { phm.PheadId, phm.MedicineId });
|
---|
| 60 | modelBuilder.Entity<PharmacyHeadMedicine>()
|
---|
| 61 | .HasOne(ph => ph.Head)
|
---|
| 62 | .WithMany(m => m.PHMedicineList)
|
---|
| 63 | .HasForeignKey(k => k.PheadId);
|
---|
| 64 |
|
---|
| 65 | modelBuilder.Entity<PharmacyHeadMedicine>()
|
---|
| 66 | .HasOne(m => m.Medicine)
|
---|
| 67 | .WithMany(ml => ml.MedicineList)
|
---|
| 68 | .HasForeignKey(k => k.MedicineId);
|
---|
| 69 |
|
---|
| 70 | modelBuilder.Entity<PharmacyHead>()
|
---|
| 71 | .HasMany(p => p.PharmaciesList)
|
---|
| 72 | .WithOne(h => h.PHead)
|
---|
| 73 | .HasForeignKey(k => k.PheadId);
|
---|
| 74 |
|
---|
[68454c6] | 75 |
|
---|
| 76 |
|
---|
[1db5673] | 77 | base.OnModelCreating(modelBuilder);
|
---|
| 78 | }
|
---|
[30a465f] | 79 | }
|
---|
| 80 | }
|
---|