source: FarmatikoData/FarmatikoDataContext.cs@ 8b13eb2

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

fix bugs

  • Property mode set to 100644
File size: 2.4 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<Pharmacy>()
30 .ToTable("Pharmacies");
31
32 modelBuilder.Entity<PharmacyHeadMedicine>()
33 .HasKey(phm => new { phm.PheadId, phm.MedicineId });
34 modelBuilder.Entity<PharmacyHeadMedicine>()
35 .HasOne(ph => ph.Head)
36 .WithMany(m => m.PHMedicineList)
37 .HasForeignKey(k => k.PheadId);
38
39 modelBuilder.Entity<PharmacyHeadMedicine>()
40 .HasOne(m => m.Medicine)
41 .WithMany(ml => ml.MedicineList)
42 .HasForeignKey(k => k.MedicineId);
43
44 modelBuilder.Entity<PharmacyHead>()
45 .HasMany(p => p.PharmaciesList)
46 .WithOne(h => h.PHead)
47 .HasForeignKey(k => k.PheadId);
48
49 /*
50 modelBuilder.Entity<CarDetails>()
51 .ToTable("CarDetails");
52
53 modelBuilder.Entity<CarDetails>()
54 .Property(x => x.Type)
55 .HasConversion<int>();
56
57 modelBuilder.Entity<CarDetails>()
58 .HasMany(x => x.ImageUrls)
59 .WithOne(y => y.Car)
60 .HasForeignKey(y => y.CarId);
61 */
62
63 /*modelBuilder.Entity<PharmacyHead>()
64 .HasMany(x => x.PharmaciesList);*/
65
66 base.OnModelCreating(modelBuilder);
67 }
68 }
69}
Note: See TracBrowser for help on using the repository browser.