079 Database access for Lookup resource of PhbkPhoneView - chempkovsky/CS82ANGULAR GitHub Wiki

Steps required to accomplish the task

  • 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 the PhbkPhoneView Lookup resource

LpdPhone

LprPhone01

  • 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!;

LprPhone02

  • 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!;

LprPhone03

  • 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!;

LprPhone04

  • 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!;

LpPhnPhBkContext

  • it repeats the code of the article 075 except for the extra foreign keys. The foreign keys which references PhbkPhone, PhbkPhoneType and PhbkEmployee for the LprPhone01, LprPhone02, LprPhone03 and LprPhone04 tables.
  • Since the code of the PhBkContext is generated by the Wizard we copied/pasted the content of the PhBkContext-file into LpPhnPhBkContext-file. We are talking about the content related to LpdPhone, 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>();

    }
}

Regenerate Views

  • 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

Regenerate LpdPhoneView and LpdPhoneViewPage

Regenerate LprPhone01View and LprPhone01ViewPage

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

project structure

Regenerate LprPhone02View and LprPhone02ViewPage

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

project structure

Regenerate LprPhone03View and LprPhone03ViewPage

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

project structure

Regenerate LprPhone04View and LprPhone04ViewPage

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

project structure

⚠️ **GitHub.com Fallback** ⚠️