034 Modeling Lookup Resource Entities for PhbkDivisionView - chempkovsky/CS82ANGULAR GitHub Wiki

Notes

  • According to the requirements 033 we need to create one of more lookup dictionary-table and one lookup refs-table per Lookup Resource.
  • for PhbkDivisionView-View we are going to create lookup resource for only one scalar property which is DivisionName. So the list of lookup dictionaries will consist of only one table.
  • for PhbkDivisionView-View we are going to create one Lookup Resource for the Along-mode and one one Lookup Resource for the one-to-many-mode. So the list of lookup refs-tables will consist of two tables.
  • since this is Modeling Lookup Resource, each created code fragment must be inside #if (!NOTMODELING) ... #endif-operators. In other words, these are pseudo-constructs that play the role of the Wizard's hints.
  • 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 dictionary

  • According to the requirements 033 the table should have two columns
    • Column for the primary key. It plays the role of the unique row id.
    • Column for the Lookup data. The unique index must be created for this column.
  • According to the requirements 033 the class declaration must be inside of #if (!NOTMODELING) ... #endif-operator.
  • DivisionRef01 and DivisionRef02 properties are the helper properties that are used by the foreign key declaration
Click to show the code
#if (!NOTMODELING)

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace PhBkEntity.PhBk
{
    public class LpdDivision
    {
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [Display(Description = "Row id", Name = "Id of the Row", Prompt = "Enter Row Id", ShortName = "Row Id")]
        [Required]
        public int DivisionNameId { 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!;

        public List<LprDivision01> DivisionRef01 { get; set; } = null!;
        public List<LprDivision02> DivisionRef02 { get; set; } = null!;
    }
}

#endif

lookup refs

  • As it was mentioned above we create two lookup refs-tables
  • According to the requirements 033 the class declaration must be inside of #if (!NOTMODELING) ... #endif-operator.

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 dictionary
    • lookup refs-table must have the foreign key which references PhbkDivision. It is a table for which we are going to create lookup resource
  • 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 LprDivision01
    {
        [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; }

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


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

        public LpdDivision DivisionNameDict { 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 dictionary
    • lookup refs-table must have the foreign key which references PhbkDivision. It is a table for which we are going to create lookup resource
    • lookup refs-table must have the foreign key which references PhbkEnterprise-table. This is because PhbkDivision references PhbkEnterprise-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 LprDivision02
    {
        [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; }

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

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


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

        public LpdDivision DivisionNameDict { get; set; } = null!;

    }
}

#endif

modification of PhbkDivision table

  • LprDivision01 and LprDivision02 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!;

#if (!NOTMODELING)
        public List<LprDivision01> DivisionRefs01 { get; set; } = null!;
        public List<LprDivision02> DivisionRefs02 { get; set; } = null!;
#endif
    }
}

modification of PhbkEnterprise table

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

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

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

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

        public List<PhbkDivision> Divisions { get; set; } = null!;

#if (!NOTMODELING)
        public List<LprDivision02> DivisionRefs02 { get; set; } = null!;
#endif

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