079 Database access for Lookup resource of PhbkPhoneView - chempkovsky/CS82ANGULAR GitHub Wiki
- We do not describe step by step instructions
- please repeat the steps similar to those described in the article 040
-
LpPhBkEntity
is the destination project for the Entities-
PhBk
is the destination folder for the Entities
-
-
LpPhBkContext
is the destination project for the Dbcontext-
PhBk
is the destination folder for the Dbcontext-
LpPhnPhBkContext
will be new Dbcontext for thePhbkPhoneView
Lookup resource
-
-
- it repeats the code of the article 074 for LpdPhone except for the namespace.
- it repeats the code of the article 074 for LprPhone01 except for the namespace.
- In addition one line of code must be removed from the class declaration:
public PhbkPhone Phone { get; set; } = null!;
- it repeats the code of the article 074 for LprPhone02 except for the namespace.
- In addition two lines of code must be removed from the class declaration:
public PhbkPhone Phone { get; set; } = null!;
public PhbkEmployee Employee { get; set; } = null!;
- it repeats the code of the article 074 for LprPhone03 except for the namespace.
- In addition two lines of code must be removed from the class declaration:
public PhbkPhone Phone { get; set; } = null!;
public PhbkPhoneType PhoneType { get; set; } = null!;
- it repeats the code of the article 074 for LprPhone04 except for the namespace.
- In addition three lines of code must be removed from the class declaration:
public PhbkPhone Phone { get; set; } = null!;
public PhbkEmployee Employee { get; set; } = null!;
public PhbkPhoneType PhoneType { get; set; } = null!;
- it repeats the code of the article 075 except for the extra foreign keys. The foreign keys which references
PhbkPhone
,PhbkPhoneType
andPhbkEmployee
for theLprPhone01
,LprPhone02
,LprPhone03
andLprPhone04
tables. - Since the code of the
PhBkContext
is generated by the Wizard wecopied/pasted
the content of thePhBkContext
-file intoLpPhnPhBkContext
-file. We are talking about the content related toLpdPhone
,LprPhone01
...LprPhone04
entities. Maybe, it's better and faster than repeating the same steps with the Wizard for the second Dbcontext.
Click to show the code
using Microsoft.EntityFrameworkCore;
using LpPhBkEntity.PhBk;
namespace LpPhBkContext.PhBk
{
public class LpPhnPhBkContext : DbContext
{
//////////////////////////////////////////////////////////////////
/// reset ".UseSqlServer"
/// reset "ConfigurationManager.ConnectionStrings"
/// optionsBuilder.UseSqlServer(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
/////////////////////////////////////////////////////////////////
// protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
// {
// optionsBuilder.UseSqlServer(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
// }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<LprPhone04>().HasKey(p => new { p.EmployeeIdRef, p.PhoneTypeIdRef, p.LpdPhoneIdRef, p.PhoneId });
modelBuilder.Entity<LprPhone03>().HasKey(p => new { p.PhoneTypeIdRef, p.LpdPhoneIdRef, p.PhoneId });
modelBuilder.Entity<LprPhone02>().HasKey(p => new { p.EmployeeIdRef, p.LpdPhoneIdRef, p.PhoneId });
modelBuilder.Entity<LprPhone01>().HasKey(p => new { p.LpdPhoneIdRef, p.PhoneId });
modelBuilder.Entity<LpdPhone>().HasAlternateKey(p => p.Phone).HasName("LpdPhoneUK");
modelBuilder.Entity<LpdPhone>().HasKey(p => p.LpdPhoneId);
modelBuilder.Entity<LprPhone01>().HasOne(d => d.PhoneDict)
.WithMany(m => m.PhoneRef01)
.HasForeignKey(d => d.LpdPhoneIdRef)
.HasPrincipalKey(p => p.LpdPhoneId)
.IsRequired(true)
.OnDelete(DeleteBehavior.NoAction);
modelBuilder.Entity<LprPhone02>().HasOne(d => d.PhoneDict)
.WithMany(m => m.PhoneRef02)
.HasForeignKey(d => d.LpdPhoneIdRef)
.HasPrincipalKey(p => p.LpdPhoneId)
.IsRequired(true)
.OnDelete(DeleteBehavior.NoAction);
modelBuilder.Entity<LprPhone03>().HasOne(d => d.PhoneDict)
.WithMany(m => m.PhoneRef03)
.HasForeignKey(d => d.LpdPhoneIdRef)
.HasPrincipalKey(p => p.LpdPhoneId)
.IsRequired(true)
.OnDelete(DeleteBehavior.NoAction);
modelBuilder.Entity<LprPhone04>().HasOne(d => d.PhoneDict)
.WithMany(m => m.PhoneRef04)
.HasForeignKey(d => d.LpdPhoneIdRef)
.HasPrincipalKey(p => p.LpdPhoneId)
.IsRequired(true)
.OnDelete(DeleteBehavior.NoAction);
}
public DbSet<LpdPhone> LpdPhoneDbSet {
get => Set<LpdPhone>();
}
public DbSet<LprPhone01> LprPhone01DbSet {
get => Set<LprPhone01>();
}
public DbSet<LprPhone02> LprPhone02DbSet {
get => Set<LprPhone02>();
}
public DbSet<LprPhone03> LprPhone03DbSet {
get => Set<LprPhone03>();
}
public DbSet<LprPhone04> LprPhone04DbSet {
get => Set<LprPhone04>();
}
}
-
We do not describe step by step instructions
- please repeat the steps similar to those described in the article 040.
-
LpPhBkContext
is the context to generate the Views -
LpPhBkEntity
is the Entities project to generate the Views -
LpPhBkViews
is the destination project for the Views-
PhBk
is the destination folder for the Views
-
- the settings are the same as those described in the article article 076 for LpdPhoneView
- the settings are as follows:
Click to show the picture
- the settings are as follows:
Click to show the picture
- the settings are as follows:
Click to show the picture
- the settings are as follows: