069 Modify DBContext for the entity with foreign key (Phone) - chempkovsky/CS82ANGULAR GitHub Wiki

Using DBContext Wizard is absolutely necessary

Steps required to accomplish the task

  • We do not describe step by step instructions

    • please repeat the steps similar to those described in the article 028.
  • Before you begin, please modify Directory.Build.props-file as it described in the Reset Directory Build props file

  • Primary key will be as follows

Click to show the picture

project structure

  • First Foreign key will be as follows
Click to show the picture

project structure

  • second Foreign key will be as follows
Click to show the picture

project structure

  • Here is a fragment of the OnModelCreating-method
...
            modelBuilder.Entity<PhbkPhone>().HasKey(p => p.PhoneId);
            modelBuilder.Entity<PhbkPhone>().HasOne(d => d.PhoneType)
                .WithMany(m => m.Phones)
                .HasForeignKey(d => d.PhoneTypeIdRef)
                .HasPrincipalKey(p => p.PhoneTypeId)
                .IsRequired(true)
                .OnDelete(DeleteBehavior.NoAction);
            modelBuilder.Entity<PhbkPhone>().HasOne(d => d.Employee)
                .WithMany(m => m.Phones)
                .HasForeignKey(d => d.EmployeeIdRef)
                .HasPrincipalKey(p => p.EmployeeId)
                .IsRequired(true)
                .OnDelete(DeleteBehavior.NoAction);
...
⚠️ **GitHub.com Fallback** ⚠️