-
Notifications
You must be signed in to change notification settings - Fork 0
061 Database access for Lookup resource of PhbkEmployeeView
chempkovsky edited this page Jun 5, 2022
·
8 revisions
- 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
-
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-
LpEmpPhBkContext
will be new Dbcontext for thePhbkEmployeeView
Lookup 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
PhbkDivision
andPhbkEmployee
for theLprEmployee02
andLprEmployee01
tables. - Since the code of the
PhBkContext
is generated by the Wizard wecopied/pasted
the content of thePhBkContext
-file intoLpEmpPhBkContext
-file. We are talking about the content related toLpdEmpLastName
, ...,LprEmployee01
,LprEmployee02
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 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.
-
LpEmpPhBkContext
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 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: