050 Modify DBContext for the entity with foreign key (Employee) - 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

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

project structure

  • Here is a fragment of the OnModelCreating-method
...
            modelBuilder.Entity<PhbkEmployee>().HasKey(p => p.EmployeeId);
            modelBuilder.Entity<PhbkEmployee>().HasOne(d => d.Division)
                .WithMany(m => m.Employees)
                .HasForeignKey(d => d.DivisionIdRef)
                .HasPrincipalKey(p => p.DivisionId)
                .IsRequired(true)
                .OnDelete(DeleteBehavior.NoAction);
...
⚠️ **GitHub.com Fallback** ⚠️