abp icon indicating copy to clipboard operation
abp copied to clipboard

Trying to extend ApbTenant with new DB field from my own module (not the the main application)

Open rlavaud opened this issue 5 years ago • 3 comments

Hi all I seem to be at a loss with extending the AbpTenant from a Module inside another module I created. I went over of the documentation on how to extend entities but the database is not reflecting the changes.

I on:

  • ABP 4.4

  • Blazor UI

  • EF Core framework

  • Steps needed to reproduce the problem.

Create a new Blazor Project Create an new ABP Module with the CLI

In the module new module Domain.Share added the new class

using System;
using System.Collections.Generic;
using System.Text;
using Volo.Abp.ObjectExtending;
using Volo.Abp.Threading;

namespace Module
{
    public static class ModuleModuleExtensionConfigurator
    {
        private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();

        public static void Configure()
        {
            OneTimeRunner.Run(() =>
            {
                ConfigureExistingProperties();
                ConfigureExtraProperties();
            });
        }

        private static void ConfigureExistingProperties()
        {
        }

        private static void ConfigureExtraProperties()
        {
          
            OneTimeRunner.Run(() =>
            {
                ObjectExtensionManager.Instance.Modules()
                  .ConfigureTenantManagement(tenantManagement =>
                  {
                      tenantManagement.ConfigureTenant(tenant =>
                      {
                          tenant.AddOrUpdateProperty<DateTime>( //property type: string
                              "CurrentPeriodEnds", //property name
                              property =>
                              {

                                  //...other configurations for this property
                              }
                          );
                      });
                  });
            });
        }
    }
}

In ModuleDomainSharedModule I added

public override void PreConfigureServices(ServiceConfigurationContext context)
        {
            ModuleModuleExtensionConfigurator.Configure();
        }

In Module.EntityFrameworkCore I added the class

public static class ModuleEfCoreEntityExtensionMappings
    {
        private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();

        public static void Configure()
        {
            ModuleGlobalFeatureConfigurator.Configure();
            ModuleModuleExtensionConfigurator.Configure();

            OneTimeRunner.Run(() =>
            {
             
                ObjectExtensionManager.Instance
                        
                        .MapEfCoreProperty<Tenant, DateTime>(
                             "CurrentPeriodEnds",
                             (entityBuilder, propertyBuilder) =>
                             {

                             }
                         );
            });
        }
    }

I seem to have hit every steps but db migrator does not create the new fields and Add Migration from the Main application does not either.

What am I am missing here.

rlavaud avatar Sep 01 '21 19:09 rlavaud

Can you share a project?

maliming avatar Sep 02 '21 01:09 maliming

@maliming yes here is a link with to the git repo example of what I am trying to get done. https://github.com/rlavaud/Bookstore

Essentially, I am trying to add a new field called CurrentPeriodEnds from the Module TenantExtension and also add the field to the DB as CurrentPeriodEnds

I assume the the Eto and Dto are trivial to extend since there is not database involved.

rlavaud avatar Sep 02 '21 14:09 rlavaud

image

maliming avatar Sep 03 '21 01:09 maliming