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