Base solution for your next web application
Open Closed

Add new param in OrganizationUnit Entity #8060


User avatar
0
SASIMEXICO created

Hi, I would like to add a new parameter "ExternalCode" to the OrganizationUnit Entity, but it is an intern class so it is "Read Only" Mode. One possible solution I have thought, would be to extend this class to a new one and add this new parameter, but I am not sure how exactly continue this way (For example: Do I have to extend also the AppService?) nor do I know if this is the best solution. Another possible solution would be to create a new class with this new parameter, and would add a relation 1-1 with OrganizationUnit. But neither this way I am sure how to set this bidirectional relational because the read-only-mode problem shows up again.

What would you do? What do you recommend?

Thanks in advance for your help.


4 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    Have you seen the Extending Existing Entities document?

    https://docs.aspnetzero.com/en/aspnet-core-angular/latest/Extending-Existing-Entities-Core-Angular

  • User Avatar
    0
    SASIMEXICO created

    I have checked this document, but I do not know how to use the Entity Generator to extend the OrganizationUnit Entity. How should I fill out the fields in order to create a new class (CustomOU) deriving from Organization Unit Entity? I assume that I need to use Entity Generator so that a new DbSet property for CustomOU entity is added automatically to DbContext class. /24h after this post/ I have been trying and finally I have created the new entity deriving from Organization Unit Entity. After doing the migration, I have checked that the new parameter "ExternalCode" has been added to OrganizationUnit table in the database. This was the first step I wanted to achieve. But now, I still have problems with the OrganizationUnitAppService. The documentation says that no changes are needed if we add this new parameter to the DTO and we use AutoMapping. But I cannot understand how is it gonna work if the repository still have the OrganizationUnit model instead of the CustomOU model.

    • Actual code:
      •       `private readonly OrganizationUnitManager _organizationUnitManager;`
        
      •       `private readonly IRepository<OrganizationUnit, long> _organizationUnitRepository;`
        

    When I do a query into this repository, I have noticed that the new parameter is not appearing.

    1. Should I add a new repository IRepository<CustomOU>?
      1. If this is the solution, only with this change would be enough to fix this problem?
      2. If I have to modify the original DTO and OrganizationUnitAppService, would be better to create new ones deriving from these, in order to not having merge conflicts with your code if there is a new update from Zero?
  • User Avatar
    0
    maliming created
    Support Team

    This is basically handled automatically by EF. It is a feature (TPH) inherited by EF

    Please see related code examples.

    https://github.com/aspnetzero/aspnet-zero-samples/tree/master/ExtendEntitiesDemo-MPA https://github.com/aspnetzero/aspnet-zero-samples/tree/master/ExtendEntitiesDemo

  • User Avatar
    0
    ismcagdas created
    Support Team

    This issue is closed because it has not had recent activity for a long time.