418.1 Modeling Lookup Resource Entities for PhbkDivision of ABP framework applications - chempkovsky/CS82ANGULAR GitHub Wiki

Notes

In case of Apb-framework we repeat all the steps described in "034 Modeling Lookup Resource Entities for PhbkDivisionView" with just one additional note regarding special columns like TetantId or ConcurrencyStamp or LastModifierId and so on. As it was noted in the requirements 033-article there are strict requirements for column names and column order in index declarations of lookup dictionary-tables and lookup refs-tables. (For instance lookup dictionary-table must be two-columns table). To be able to include special columns in the list for transfer, we modified wizard's analizers which accept any number of extra properties. Such extra properties must have [Description("DictHelper")]-attribute.

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
  • TenantId is the additional property we mentioned above. And it has [Description("DictHelper")]-attribute.
  • public int DivisionNameId { get; protected set; } is used as a primary key column. We can not use Id-name since LprDivision01 and LprDivision02 entities already have Id-column wich references the primary key of the PhbkDivision-entity.
Click to show the code
#if (!NOTMODELING)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Volo.Abp;
using Volo.Abp.Domain.Entities;
using Volo.Abp.MultiTenancy;

namespace rupbes.firstapp.Phbk
{
    public class LpdDivision : Entity, IMultiTenant
    {
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [Display(Description = "Row id", Name = "Id of the Row", Prompt = "Enter Row Id", ShortName = "Row Id")]
        [Required]
        public int DivisionNameId { get; protected 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 = "Tenant id", Name = "Tenant Id", Prompt = "Enter Tenant Id", ShortName = "Tenant Id")]
        [Description("DictHelper")]
        public virtual Guid? TenantId { get; protected set; }

        public LpdDivision() : base()
        {
            
        }

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


        public LpdDivision( string divisionName) : base()
        {
            Check.NotNullOrWhiteSpace(divisionName, nameof(DivisionName));
            DivisionName = divisionName;
        }

        public virtual void ChangeVals(string divisionName)
        {
            Check.NotNullOrWhiteSpace(divisionName, nameof(DivisionName));
            DivisionName = divisionName;
        }

        public override object?[] GetKeys()
        {
            return new object[] { DivisionNameId };
        }

    }
}

#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;
using Volo.Abp.Domain.Entities;

namespace rupbes.firstapp.Phbk
{
    public class LprDivision01 : Entity
    {
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        [Display(Description = "Row id", Name = "Id of the Division", Prompt = "Enter Division Id", ShortName = "Division Id")]
        [Required]
        public int Id { get; set; }


        [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 override object?[] GetKeys()
        {
            return new object[] { DivisionNameIdRef, Id };
        }

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

        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;
using Volo.Abp.Domain.Entities;

namespace rupbes.firstapp.Phbk
{
    public class LprDivision02 : Entity
    {
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        [Display(Description = "Row id", Name = "Id of the Division", Prompt = "Enter Division Id", ShortName = "Division Id")]
        [Required]
        public int Id { get; set; }


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


        [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 override object?[] GetKeys()
        {
            return new object[] { EntrprsIdRef, DivisionNameIdRef, Id };
        }

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

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

        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;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Volo.Abp;
using Volo.Abp.Auditing;
using Volo.Abp.Domain.Entities;
using Volo.Abp.MultiTenancy;

namespace rupbes.firstapp.Phbk
{
    [Description()]
    public class PhbkDivision : Entity<int>, IMultiTenant, IHasConcurrencyStamp
    {
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        [Display(Description = "Row id", Name = "Id of the Division", Prompt = "Enter Division Id", ShortName = "Division Id")]
        [Required]
        public override int Id { get; protected 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; }

        [DisableAuditing]
        [Display(Description = "Concurrency Stamp", Name = "Concurrency Stamp", Prompt = "Enter Concurrency Stamp", ShortName = "Concurrency Stamp")]
        [StringLength(40, MinimumLength = 0, ErrorMessage = "Invalid")]
        [Required]
        [ConcurrencyCheck]
        public virtual string ConcurrencyStamp { get; set; } = default!;


        [Display(Description = "Tenant id", Name = "Tenant Id", Prompt = "Enter Tenant Id", ShortName = "Tenant Id")]
        public virtual Guid? TenantId { get; protected set; }


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

#if (!NOTMODELING)
        public PhbkEnterprise Enterprise { get; set; } = null!;
        public List<PhbkEmployee> Employees { get; set; } = null!;
#endif

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

        public PhbkDivision() : base()
        {
            ConcurrencyStamp = Guid.NewGuid().ToString("N");
        }

        public PhbkDivision(int id, string divisionName, string? divisionDesc, int entrprsIdRef) : base(id)
        {
            Check.NotNullOrWhiteSpace(divisionName, nameof(DivisionName));
            DivisionName = divisionName;
            DivisionDesc = divisionDesc;
            EntrprsIdRef = entrprsIdRef;
            ConcurrencyStamp = Guid.NewGuid().ToString("N");
        }

        public virtual void ChangeVals(string divisionName, string? divisionDesc, int entrprsIdRef, string concurrencyStamp)
        {
            Check.NotNullOrWhiteSpace(divisionName, nameof(DivisionName));
            DivisionName = divisionName;
            DivisionDesc = divisionDesc;
            EntrprsIdRef = entrprsIdRef;
            ConcurrencyStamp = concurrencyStamp;
        }

    }
}

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;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Volo.Abp;
using Volo.Abp.Auditing;
using Volo.Abp.Domain.Entities;
using Volo.Abp.MultiTenancy;

namespace rupbes.firstapp.Phbk
{
    [Description()]
    public class PhbkEnterprise : Entity<int>, IMultiTenant, IHasConcurrencyStamp
    {
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        [Display(Description = "Row id", Name = "Id of the Enterprise", Prompt = "Enter Enterprise  Id", ShortName = "Enterprise Id")]
        [Required]
        public override int Id { get; protected set; } = default!;

        [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; protected 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; protected set; }

        [DisableAuditing]
        [Display(Description = "Concurrency Stamp", Name = "Concurrency Stamp", Prompt = "Enter Concurrency Stamp", ShortName = "Concurrency Stamp")]
        [StringLength(40, MinimumLength = 0, ErrorMessage = "Invalid")]
        [Required]
        [ConcurrencyCheck]
        public virtual string ConcurrencyStamp { get; set; } = default!;


        [Display(Description = "Tenant id", Name = "Tenant Id", Prompt = "Enter Tenant Id", ShortName = "Tenant Id")]
        public virtual Guid? TenantId { get; protected set; }

        public PhbkEnterprise() : base()
        {
            ConcurrencyStamp = Guid.NewGuid().ToString("N");
        }

        public PhbkEnterprise(int id, string entrprsName, string? entrprsDesc) : base(id)
        {
            Check.NotNullOrWhiteSpace(entrprsName, nameof(EntrprsName));
            EntrprsName = entrprsName;
            EntrprsDesc = entrprsDesc;
            ConcurrencyStamp = Guid.NewGuid().ToString("N");
        }

        public virtual void ChangeVals(string entrprsName, string? entrprsDesc, string concurrencyStamp)
        {
            Check.NotNullOrWhiteSpace(entrprsName, nameof(EntrprsName));
            EntrprsName = entrprsName;
            EntrprsDesc = entrprsDesc;
            ConcurrencyStamp = concurrencyStamp;
        }

#if (!NOTMODELING)
        public virtual List<PhbkDivision> Divisions { get; set; } = null!;
#endif

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

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