source: FarmatikoData/FarmatikoDataContext.cs@ 8e74e2f

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

Fix bugs, add some more.

  • Property mode set to 100644
File size: 2.8 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.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<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
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
75
76
77 base.OnModelCreating(modelBuilder);
78 }
79 }
80}
Note: See TracBrowser for help on using the repository browser.