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) { }
|
---|
9 |
|
---|
10 |
|
---|
11 | public DbSet<HealthFacility> HealthFacilities { get; set; }
|
---|
12 | public DbSet<HealthcareWorker> HealthcareWorkers { get; set; }
|
---|
13 | public DbSet<Pharmacy> Pharmacies { get; set; }
|
---|
14 | public DbSet<PharmacyHead> PharmacyHeads { get; set; }
|
---|
15 | public DbSet<Pandemic> Pandemics { get; set; }
|
---|
16 | public DbSet<Medicine> Medicines { get; set; }
|
---|
17 | public DbSet<RequestPharmacyHead> PHRequests { get; set; }
|
---|
18 | public DbSet<User> Users { get; set; }
|
---|
19 | public DbSet<PharmacyHeadMedicine> PharmacyHeadMedicines { get; set; }
|
---|
20 |
|
---|
21 | protected override void OnModelCreating(ModelBuilder modelBuilder)
|
---|
22 | {
|
---|
23 | modelBuilder.UseSerialColumns();
|
---|
24 |
|
---|
25 | modelBuilder.Entity<PharmacyHead>()
|
---|
26 | .ToTable("PharmacyHeads");
|
---|
27 |
|
---|
28 | modelBuilder.Entity<Medicine>()
|
---|
29 | .ToTable("Medicines");
|
---|
30 |
|
---|
31 | modelBuilder.Entity<Pharmacy>()
|
---|
32 | .ToTable("Pharmacies");
|
---|
33 |
|
---|
34 | modelBuilder.Entity<PharmacyHeadMedicine>()
|
---|
35 | .ToTable("PharmacyHeadMedicines");
|
---|
36 |
|
---|
37 | modelBuilder.Entity<RequestPharmacyHead>()
|
---|
38 | .ToTable("PHRequests");
|
---|
39 |
|
---|
40 | modelBuilder.Entity<PharmacyHead>()
|
---|
41 | .Property(p => p.Id)
|
---|
42 | .ValueGeneratedOnAdd();
|
---|
43 |
|
---|
44 | modelBuilder.Entity<PharmacyHeadMedicine>()
|
---|
45 | .Property(p => p.Id)
|
---|
46 | .ValueGeneratedOnAdd();
|
---|
47 |
|
---|
48 | modelBuilder.Entity<Medicine>()
|
---|
49 | .Property(p => p.Id)
|
---|
50 | .ValueGeneratedOnAdd();
|
---|
51 |
|
---|
52 | modelBuilder.Entity<Pharmacy>()
|
---|
53 | .Property(p => p.Id)
|
---|
54 | .ValueGeneratedOnAdd();
|
---|
55 |
|
---|
56 | modelBuilder.Entity<PharmacyHead>()
|
---|
57 | .HasMany<Pharmacy>(p => p.Pharmacies)
|
---|
58 | .WithOne(p => p.PharmacyHead);
|
---|
59 |
|
---|
60 | modelBuilder.Entity<Pharmacy>()
|
---|
61 | .HasOne<PharmacyHead>(p => p.PharmacyHead)
|
---|
62 | .WithMany(p => p.Pharmacies)
|
---|
63 | .HasForeignKey(x => x.PheadId);
|
---|
64 |
|
---|
65 | modelBuilder.Entity<PharmacyHeadMedicine>()
|
---|
66 | .HasKey(bc => new { bc.PheadId, bc.MedicineId});
|
---|
67 |
|
---|
68 | modelBuilder.Entity<PharmacyHeadMedicine>()
|
---|
69 | .HasOne(bc => bc.Head)
|
---|
70 | .WithMany(b => b.Medicines)
|
---|
71 | .HasForeignKey(bc => bc.PheadId);
|
---|
72 |
|
---|
73 | modelBuilder.Entity<PharmacyHeadMedicine>()
|
---|
74 | .HasOne(bc => bc.Medicine)
|
---|
75 | .WithMany(c => c.Medicines)
|
---|
76 | .HasForeignKey(bc => bc.MedicineId);
|
---|
77 |
|
---|
78 |
|
---|
79 | base.OnModelCreating(modelBuilder);
|
---|
80 | }
|
---|
81 | }
|
---|
82 | }
|
---|