061 Database access for Lookup resource of PhbkEmployeeView - chempkovsky/CS82ANGULAR GitHub Wiki
- LpdEmpLastName
- LpdEmpFirstName
- LpdEmpSecondName
- LprEmployee01
- LprEmployee02
- LpEmpPhBkContext
- Regenerate Views
- We do not describe step by step instructions
- please repeat the steps similar to those described in the article 040
-
LpPhBkEntityis the destination project for the Entities-
PhBkis the destination folder for the Entities
-
-
LpPhBkContextis the destination project for the Dbcontext-
PhBkis the destination folder for the Dbcontext-
LpEmpPhBkContextwill be new Dbcontext for thePhbkEmployeeViewLookup resource
-
-
- it repeats the code of the article 056 for EmpLastName except for the namespace.
- it repeats the code of the article 056 for LpdEmpFirstName except for the namespace.
- it repeats the code of the article 056 for LpdEmpSecondName except for the namespace.
- it repeats the code of the article 056 for LprEmployee01 except for the namespace.
- In addition one line of code must be removed from the class declaration:
public PhbkEmployee Employee { get; set; } = null!;- it repeats the code of the article 056 for LprEmployee02 except for the namespace.
- In addition two lines of code must be removed from the class declaration:
public PhbkEmployee Employee { get; set; } = null!;
public PhbkDivision Division { get; set; } = null!;- it repeats the code of the article 057 except for the extra foreign keys. The foreign keys which references
PhbkDivisionandPhbkEmployeefor theLprEmployee02andLprEmployee01tables. - Since the code of the
PhBkContextis generated by the Wizard wecopied/pastedthe content of thePhBkContext-file intoLpEmpPhBkContext-file. We are talking about the content related toLpdEmpLastName, ...,LprEmployee01,LprEmployee02entities. 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 LpEmpPhBkContext : DbContext
{
public LpEmpPhBkContext(DbContextOptions<LpPhbkDbContext> options)
: base(options)
{
Database.EnsureCreated();
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<LprEmployee02>().HasKey(p => new { p.DivisionIdRef, p.EmpLastNameIdRef, p.EmpFirstNameIdRef, p.EmpSecondNameIdRef, p.EmployeeId });
modelBuilder.Entity<LprEmployee01>().HasKey(p => new { p.EmpLastNameIdRef, p.EmpFirstNameIdRef, p.EmpSecondNameIdRef, p.EmployeeId });
modelBuilder.Entity<LpdEmpSecondName>().HasAlternateKey(p => p.EmpSecondName).HasName("LpdEmpSecondNameUK");
modelBuilder.Entity<LpdEmpSecondName>().HasKey(p => p.EmpSecondNameId);
modelBuilder.Entity<LpdEmpFirstName>().HasAlternateKey(p => p.EmpFirstName).HasName("LpdEmpFirstNameUK");
modelBuilder.Entity<LpdEmpFirstName>().HasKey(p => p.EmpFirstNameId);
modelBuilder.Entity<LpdEmpLastName>().HasAlternateKey(p => p.EmpLastName).HasName("LpdEmpLastNameUK");
modelBuilder.Entity<LpdEmpLastName>().HasKey(p => p.EmpLastNameId);
modelBuilder.Entity<LprEmployee02>().HasOne(d => d.EmpLastNameDict)
.WithMany(m => m.EmployeeRef02)
.HasForeignKey(d => d.EmpLastNameIdRef)
.HasPrincipalKey(p => p.EmpLastNameId)
.IsRequired(true)
.OnDelete(DeleteBehavior.NoAction);
modelBuilder.Entity<LprEmployee02>().HasOne(d => d.EmpFirstNameDict)
.WithMany(m => m.EmployeeRef02)
.HasForeignKey(d => d.EmpFirstNameIdRef)
.HasPrincipalKey(p => p.EmpFirstNameId)
.IsRequired(true)
.OnDelete(DeleteBehavior.NoAction);
modelBuilder.Entity<LprEmployee02>().HasOne(d => d.EmpSecondNameDict)
.WithMany(m => m.EmployeeRef02)
.HasForeignKey(d => d.EmpSecondNameIdRef)
.HasPrincipalKey(p => p.EmpSecondNameId)
.IsRequired(true)
.OnDelete(DeleteBehavior.NoAction);
modelBuilder.Entity<LprEmployee01>().HasOne(d => d.EmpLastNameDict)
.WithMany(m => m.EmployeeRef01)
.HasForeignKey(d => d.EmpLastNameIdRef)
.HasPrincipalKey(p => p.EmpLastNameId)
.IsRequired(true)
.OnDelete(DeleteBehavior.NoAction);
modelBuilder.Entity<LprEmployee01>().HasOne(d => d.EmpFirstNameDict)
.WithMany(m => m.EmployeeRef01)
.HasForeignKey(d => d.EmpFirstNameIdRef)
.HasPrincipalKey(p => p.EmpFirstNameId)
.IsRequired(true)
.OnDelete(DeleteBehavior.NoAction);
modelBuilder.Entity<LprEmployee01>().HasOne(d => d.EmpSecondNameDict)
.WithMany(m => m.EmployeeRef01)
.HasForeignKey(d => d.EmpSecondNameIdRef)
.HasPrincipalKey(p => p.EmpSecondNameId)
.IsRequired(true)
.OnDelete(DeleteBehavior.NoAction);
}
public DbSet<LpdEmpLastName> LpdEmpLastNameDbSet {
get => Set<LpdEmpLastName>();
}
public DbSet<LpdEmpFirstName> LpdEmpFirstNameDbSet {
get => Set<LpdEmpFirstName>();
}
public DbSet<LpdEmpSecondName> LpdEmpSecondNameDbSet {
get => Set<LpdEmpSecondName>();
}
public DbSet<LprEmployee01> LprEmployee01DbSet {
get => Set<LprEmployee01>();
}
public DbSet<LprEmployee02> LprEmployee02DbSet {
get => Set<LprEmployee02>();
}
}
}-
We do not describe step by step instructions
- please repeat the steps similar to those described in the article 040.
-
LpEmpPhBkContextis the context to generate the Views -
LpPhBkEntityis the Entities project to generate the Views -
LpPhBkViewsis the destination project for the Views-
PhBkis the destination folder for the Views
-
- the settings are the same as those described in the article article 058 for LpdEmpLastNameView
- the settings are the same as those described in the article article 058 for LpdEmpFirstNameViewPage
- the settings are the same as those described in the article article 058 for LpdEmpLastNameView
- the settings are as follows:
Click to show the picture

- the settings are as follows:
Click to show the picture
