050 Modify DBContext for the entity with foreign key (Employee) - chempkovsky/CS82ANGULAR GitHub Wiki
-
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
- Foreign key will be as follows
Click to show the picture
- 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);
...
- after you finish, please modify
Directory.Build.props
-file as it described in the Reset Directory Build props file again