source: FarmatikoData/FarmatikoDataContext.cs@ 0a694bb

Last change on this file since 0a694bb was 0a694bb, checked in by Dimitar Slezenkovski <dslezenkovski@…>, 20 months ago

Fix create new user bug.

  • 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 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<Medicine>()
45 .Property(x => x.Id)
46 .HasIdentityOptions(startValue: 1);
47
48 modelBuilder.Entity<Pharmacy>()
49 .Property(x => x.Id)
50 .HasIdentityOptions(startValue: 1);
51
52 modelBuilder.Entity<PharmacyHead>()
53 .Property(x => x.Id)
54 .HasIdentityOptions(startValue: 1);
55
56 modelBuilder.Entity<PharmacyHeadMedicine>()
57 .Property(x => x.Id)
58 .HasIdentityOptions(startValue: 1);
59
60 modelBuilder.Entity<RequestPharmacyHead>()
61 .Property(x => x.Id)
62 .HasIdentityOptions(startValue: 1);*/
63
64 /*modelBuilder.Entity<User>()
65 .Property(x => x.Id)
66 .HasIdentityOptions(startValue: 1);
67
68 modelBuilder.Entity<PharmacyHeadMedicine>()
69 .HasKey(phm => new { phm.PheadId, phm.MedicineId });
70
71 modelBuilder.Entity<PharmacyHead>()
72 .HasMany<Pharmacy>(p => p.Pharmacy)
73 .WithOne(p => p.PharmacyHead)
74 .HasForeignKey();
75
76 modelBuilder.Entity<Pharmacy>()
77 .HasOne<PharmacyHead>(p => p.PharmacyHead)
78 .WithMany(p => p.Pharmacy);
79 */
80
81 base.OnModelCreating(modelBuilder);
82 }
83 }
84}
Note: See TracBrowser for help on using the repository browser.