056 Modeling Composite Lookup Resource Entities for PhbkEmployee - chempkovsky/CS82ANGULAR GitHub Wiki

Notes

  • We say that a Lookup Resource is Composite if it has more than one search property.
  • We are going to create a lookup resource for three scalar properties:
    • EmpLastName
    • EmpFirstName
    • EmpSecondName
  • the end user can define a partial filter
    • for one prop: EmpLastName
    • for two prop: EmpLastName and EmpFirstName
  • According to the requirements 033 we need to create three lookup dictionary-table and two lookup refs-table. (The number of the lookup refs-tables depends on the number of the foreign keys)
  • each dictionary table
    • should have two columns:
      • row id column with a primary key on it
      • data column with a unique key on it
      • the name of the data column must be the same as column name of the PhbkEmployee-table
  • Naming prefix for the lookup dictionary-tables will be Lpd (which means lookup dictionary)
  • Naming prefix for the lookup refs-tables will be Lpr (which means lookup refs)

Lookup dictionaries

Lookup dictionary for EmpLastName

  • LpdEmpLastName will be the name of the dictionary table
  • According to the requirements 033 the class declaration must be inside of #if (!NOTMODELING) ... #endif-operator.
Click to show the code
#if (!NOTMODELING)
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace PhBkEntity.PhBk
{
    public class LpdEmpLastName
    {

        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [Display(Description = "Row id", Name = "Id of the Row", Prompt = "Enter Row Id", ShortName = "Row Id")]
        [Required]
        public int EmpLastNameId { get; set; }

        [Display(Description = "Last Name of the Employee", Name = "Employee Last Name", Prompt = "Enter Employee Last Name", ShortName = "Last Name")]
        [StringLength(40, MinimumLength = 3, ErrorMessage = "Invalid")]
        [Required]
        public string EmpLastName { get; set; } = null!;

        public List<LprEmployee01> EmployeeRef01 { get; set; } = null!;
        public List<LprEmployee02> EmployeeRef02 { get; set; } = null!;
    }
}
#endif

Lookup dictionary for EmpFirstName

  • LpdEmpFirstName will be the name of the dictionary table
  • According to the requirements 033 the class declaration must be inside of #if (!NOTMODELING) ... #endif-operator.
Click to show the code
#if (!NOTMODELING)
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace PhBkEntity.PhBk
{
    public class LpdEmpFirstName
    {
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [Display(Description = "Row id", Name = "Id of the Row", Prompt = "Enter Row Id", ShortName = "Row Id")]
        [Required]
        public int EmpFirstNameId { get; set; }

        [Display(Description = "First Name of the Employee", Name = "Employee First Name", Prompt = "Enter Employee First Name", ShortName = "First Name")]
        [StringLength(25, MinimumLength = 3, ErrorMessage = "Invalid")]
        [Required]
        public string EmpFirstName { get; set; } = null!;

        public List<LprEmployee01> EmployeeRef01 { get; set; } = null!;
        public List<LprEmployee02> EmployeeRef02 { get; set; } = null!;
    }
}
#endif

Lookup dictionary for EmpSecondName

  • LpdEmpSecondName will be the name of the dictionary table
  • According to the requirements 033 the class declaration must be inside of #if (!NOTMODELING) ... #endif-operator.
Click to show the code
#if (!NOTMODELING)
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace PhBkEntity.PhBk
{
    public class LpdEmpSecondName
    {
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [Display(Description = "Row id", Name = "Id of the Row", Prompt = "Enter Row Id", ShortName = "Row Id")]
        [Required]
        public int EmpSecondNameId { get; set; }

        [Display(Description = "Row id", Name = "Employee Second Name", Prompt = "Enter Employee Second Name", ShortName = "Second Name")]
        [StringLength(25, ErrorMessage = "Invalid")]
        public string EmpSecondName { get; set; } = string.Empty;

        public List<LprEmployee01> EmployeeRef01 { get; set; } = null!;
        public List<LprEmployee02> EmployeeRef02 { get; set; } = null!;
    }
}
#endif

refs tables

lookup refs for along mode

  • along-mode is a mode in which the component is not used as detail node in master-detail navigation chain and in which the component is not used as detail panel on the one-to-many-page.

  • According to the requirements 033

    • lookup refs-table must have the foreign key which references lookup dictionaries
    • lookup refs-table must have the foreign key which references PhbkEmployee. It is a table for which we are going to create lookup resource
  • LprEmployee01 will be the name for the table

  • According to the requirements 033 the class declaration must be inside of #if (!NOTMODELING) ... #endif-operator.

Click to show the code
#if (!NOTMODELING)
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace PhBkEntity.PhBk
{
    public class LprEmployee01
    {
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        [Display(Description = "Row id", Name = "Id of the Employee", Prompt = "Enter Employee  Id", ShortName = "Employee Id")]
        [Required]
        public int EmployeeId { get; set; }

        public PhbkEmployee Employee { get; set; } = null!;

        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        [Display(Description = "Row ref id", Name = "ref Id of the Row", Prompt = "Enter Row ref Id", ShortName = "Row ref Id")]
        [Required]
        public int EmpLastNameIdRef { get; set; }

        public LpdEmpLastName EmpLastNameDict { get; set; } = null!;

        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        [Display(Description = "Row ref id", Name = "ref Id of the Row", Prompt = "Enter Row ref Id", ShortName = "Row ref Id")]
        [Required]
        public int EmpFirstNameIdRef { get; set; }

        public LpdEmpFirstName EmpFirstNameDict { get; set; } = null!;

        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        [Display(Description = "S name ref id", Name = "Id of the Row", Prompt = "Enter Row Id", ShortName = "Row Id")]
        [Required]
        public int EmpSecondNameIdRef { get; set; }

        public LpdEmpSecondName EmpSecondNameDict { get; set; } = null!;
    }
}
#endif

lookup refs for one to many mode

  • one-to-many-mode is a mode in which the component is used as detail node in master-detail navigation chain or in which the component is used as detail panel on the one-to-many-page.
  • According to the requirements 033
    • lookup refs-table must have the foreign key which references lookup dictionaries
    • lookup refs-table must have the foreign key which references PhbkEmployee. It is a table for which we are going to create lookup resource
    • lookup refs-table must have the foreign key which references PhbkDivision-table. This is because PhbkEmployee references PhbkDivision-table as well.
  • According to the requirements 033 the class declaration must be inside of #if (!NOTMODELING) ... #endif-operator.
Click to show the code
#if (!NOTMODELING)
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace PhBkEntity.PhBk
{
    public class LprEmployee02
    {
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        [Display(Description = "Emp Row id", Name = "Id of the Employee", Prompt = "Enter Employee Id", ShortName = "Employee Id")]
        [Required]
        public int EmployeeId { get; set; }

        public PhbkEmployee Employee { get; set; } = null!;

        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        [Display(Description = "Lst name ref id", Name = "Lst name  ref Id", Prompt = "Enter Lst name ref Id", ShortName = "Lst name ref Id")]
        [Required]
        public int EmpLastNameIdRef { get; set; }

        public LpdEmpLastName EmpLastNameDict { get; set; } = null!;

        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        [Display(Description = "Frst name ref id", Name = "Frst name  ref Id", Prompt = "Enter Frst name ref Id", ShortName = "Frst name ref Id")]
        [Required]
        public int EmpFirstNameIdRef { get; set; }

        public LpdEmpFirstName EmpFirstNameDict { get; set; } = null!;

        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        [Display(Description = "Sec name ref id", Name = "Sec name  ref Id", Prompt = "Enter Sec name ref Id", ShortName = "Sec name ref Id")]
        [Required]
        public int EmpSecondNameIdRef { get; set; }

        public LpdEmpSecondName EmpSecondNameDict { get; set; } = null!;

        [Display(Description = "Division Row id", Name = "Id of the Division", Prompt = "Enter Division Id", ShortName = "Division Id")]
        [Required]
        public int DivisionIdRef { get; set; }

        public PhbkDivision Division { get; set; } = null!;
    }
}
#endif

modification of PhbkEmployee table

  • LprEmployee01 and LprEmployee02 references PhbkEmployee-table. To accomplish the foreign key declaration we need to add inverse reference in the PhbkEmployee-table.
  • According to the requirements 033 the inverse reference code must be inside of #if (!NOTMODELING) ... #endif-operator.
  • Here is a new version PhbkEmployee-table.
Click to show the code
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace PhBkEntity.PhBk
{
    public class PhbkEmployee
    {
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [Display(Description = "Row id", Name = "Id of the Employee", Prompt = "Enter Employee  Id", ShortName = "Employee Id")]
        [Required]
        public int EmployeeId { get; set; }

        [Display(Description = "First Name of the Employee", Name = "Employee First Name", Prompt = "Enter Employee First Name", ShortName = "First Name")]
        [StringLength(25, MinimumLength = 3, ErrorMessage = "Invalid")]
        [Required]
        public string EmpFirstName { get; set; } = null!;

        [Display(Description = "Last Name of the Employee", Name = "Employee Last Name", Prompt = "Enter Employee Last Name", ShortName = "Last Name")]
        [StringLength(40, MinimumLength = 3, ErrorMessage = "Invalid")]
        [Required]
        public string EmpLastName { get; set; } = null!;

        [Display(Description = "Row id", Name = "Employee Second Name", Prompt = "Enter Employee Second Name", ShortName = "Second Name")]
        [StringLength(25, ErrorMessage = "Invalid")]
        public string? EmpSecondName { get; set; }

        [Display(Description = "Row id", Name = "Id of the Division", Prompt = "Enter Division Id", ShortName = "Division Id")]
        [Required]
        public int DivisionIdRef { get; set; }

        public PhbkDivision Division { get; set; } = null!;

#if (!NOTMODELING)
        public List<LprEmployee01> EmployeeRefs01 { get; set; } = null!;
        public List<LprEmployee02> EmployeeRefs02 { get; set; } = null!;
#endif

    }
}

modification of PhbkDivision table

  • LprEmployee02 references PhbkDivision-table. To accomplish the foreign key declaration we need to add inverse reference in the PhbkDivision-table.
  • According to the requirements 033 the inverse reference code must be inside of #if (!NOTMODELING) ... #endif-operator.
  • Here is a new version PhbkDivision-table.
Click to show the code
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace PhBkEntity.PhBk
{
    public class PhbkDivision
    {
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        [Display(Description = "Row id", Name = "Id of the Division", Prompt = "Enter Division Id", ShortName = "Division Id")]
        [Required]
        public int DivisionId { get; set; }

        [Display(Description = "Name of the Enterprise Division", Name = "Name of the Division", Prompt = "Enter Division Name", ShortName = "Division Name")]
        [StringLength(20, MinimumLength = 3, ErrorMessage = "Invalid")]
        [Required]
        public string DivisionName { get; set; } = null!;

        [Display(Description = "Description of the Enterprise Division", Name = "Description of the Division", Prompt = "Enter Enterprise Division Description", ShortName = "Division Description")]
        [StringLength(250, ErrorMessage = "Invalid")]
        public string? DivisionDesc { get; set; }

        [Display(Description = "Row id", Name = "Id of the Enterprise", Prompt = "Enter Enterprise  Id", ShortName = "Enterprise Id")]
        [Required]
        public int EntrprsIdRef { get; set; }

        public PhbkEnterprise Enterprise { get; set; } = null!;

        public List<PhbkEmployee> Employees { get; set; } = null!;

#if (!NOTMODELING)
        public List<LprDivision01> DivisionRefs01 { get; set; } = null!;
        public List<LprDivision02> DivisionRefs02 { get; set; } = null!;
        public List<LprEmployee02> EmployeeRefs02 { get; set; } = null!;
#endif
    }
}
⚠️ **GitHub.com Fallback** ⚠️