049 Entity with ForeignKey : Employee - chempkovsky/CS82ANGULAR GitHub Wiki

According to the rules defined in the article 006 Development Process Cycle

We can continue with any entity from the list: Employee Let's continue with PhbkEmployee

  • Step #1:
    • Run Visual Studio and Open PhonebookSolution- solution
      • Right Click PhBk of the PhBkEntity-project
      • Select Add/Class-menu item
      • In the dialog enter the name for the class
      • PhbkEmployee
      • Click Add-button
  • Step #2:
    • Open PhbkEmployee.cs-file and modify the body of the class as it is shown on the slide
Click to show the PhbkEmployee.cs file
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!;


    }
}
  • PhbkEmployee refers to PhbkDivision as the master entity.
  • to complete description of the Foreign Key PhbkDivision needs to be modified as it is shown below:
Click to show the PhbkDivision.cs file
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!;
#endif
    }
}
⚠️ **GitHub.com Fallback** ⚠️