027 Entity with ForeignKey : Division - 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: Division
Let's continue with PhbkDivision
- Step #1:
- Run Visual Studio and Open
PhonebookSolution- solution- Right Click
PhBkof thePhBkEntity-project - Select
Add/Class-menu item - In the dialog enter the name for the class
- PhbkDivision
- Click
Add-button
- Right Click
- Run Visual Studio and Open
- Step #2:
- Open
PhbkDivision.cs-file and modify the body of the class as it is shown on the slide
- Open
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!;
}
}-
PhbkDivisionrefers toPhbkEnterpriseas the master entity. - to complete description of the Foreign Key
PhbkEnterpriseneeds to be modified as it is shown below:
Click to show the PhbkEnterprise.cs file
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!;
}
}- PhBkEntity project becomes as follows
Click to show the project structure
