Ignore:
Timestamp:
02/08/21 16:39:25 (3 years ago)
Author:
Dimitar Slezenkovski <dslezenkovski@…>
Branches:
master
Children:
8eb1e21, dae4cde
Parents:
0a694bb
Message:

Fix all bugs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • FarmatikoData/FarmatikoDataContext.cs

    r0a694bb re0cdea2  
    4242                .ValueGeneratedOnAdd();
    4343
    44             /*modelBuilder.Entity<Medicine>()
    45                 .Property(x => x.Id)
    46                 .HasIdentityOptions(startValue: 1);
     44            modelBuilder.Entity<PharmacyHeadMedicine>()
     45                .Property(p => p.Id)
     46                .ValueGeneratedOnAdd();
     47
     48            modelBuilder.Entity<Medicine>()
     49                .Property(p => p.Id)
     50                .ValueGeneratedOnAdd();
    4751
    4852            modelBuilder.Entity<Pharmacy>()
    49                 .Property(x => x.Id)
    50                 .HasIdentityOptions(startValue: 1);
     53                .Property(p => p.Id)
     54                .ValueGeneratedOnAdd();
    5155
    5256            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();
     57                .HasMany<Pharmacy>(p => p.Pharmacies)
     58                .WithOne(p => p.PharmacyHead);
    7559
    7660            modelBuilder.Entity<Pharmacy>()
    7761                .HasOne<PharmacyHead>(p => p.PharmacyHead)
    78                 .WithMany(p => p.Pharmacy);
    79             */
     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
    8078
    8179            base.OnModelCreating(modelBuilder);
Note: See TracChangeset for help on using the changeset viewer.