source: FarmatikoData/FarmatikoDataContext.cs@ 1db5673

Last change on this file since 1db5673 was 1db5673, checked in by DimitarSlezenkovski <dslezenkovski@…>, 2 years ago

Fix bugs, add some more

  • Property mode set to 100644
File size: 1.9 KB
Line 
1using FarmatikoData.Models;
2using Microsoft.EntityFrameworkCore;
3
4namespace FarmatikoData
5{
6 public class FarmatikoDataContext : DbContext
7 {
8 public FarmatikoDataContext(DbContextOptions options) : base(options) { }
9
10
11 public virtual DbSet<HealthFacility> HealthFacilities { get; set; }
12 public virtual DbSet<HealthcareWorker> HealthcareWorkers { get; set; }
13 public virtual DbSet<Pharmacy> Pharmacies { get; set; }
14 public virtual DbSet<PharmacyHead> PharmacyHeads { get; set; }
15 public virtual DbSet<Pandemic> Pandemics { get; set; }
16 public virtual DbSet<Medicine> Medicines { get; set; }
17 public virtual DbSet<RequestPharmacyHead> PHRequests { get; set; }
18 public virtual DbSet<User> Users { get; set; }
19 public virtual DbSet<PharmacyHeadMedicine> PharmacyHeadMedicines { get; set; }
20
21 protected override void OnModelCreating(ModelBuilder modelBuilder)
22 {
23 modelBuilder.Entity<PharmacyHead>()
24 .ToTable("PharmacyHeads");
25
26 modelBuilder.Entity<Medicine>()
27 .ToTable("Medicines");
28
29 modelBuilder.Entity<PharmacyHeadMedicine>()
30 .HasKey(phm => new { phm.PheadId, phm.MedicineId });
31 modelBuilder.Entity<PharmacyHeadMedicine>()
32 .HasOne(ph => ph.Head)
33 .WithMany(m => m.PHMedicineList)
34 .HasForeignKey(k => k.PheadId);
35
36 modelBuilder.Entity<PharmacyHeadMedicine>()
37 .HasOne(m => m.Medicine)
38 .WithMany(ml => ml.MedicineList)
39 .HasForeignKey(k => k.MedicineId);
40
41 modelBuilder.Entity<PharmacyHead>()
42 .HasMany(p => p.PharmaciesList)
43 .WithOne(h => h.PHead)
44 .HasForeignKey(k => k.PheadId);
45
46 base.OnModelCreating(modelBuilder);
47 }
48 }
49}
Note: See TracBrowser for help on using the repository browser.