Search code examples
c#typescriptabp-framework

Extension on SaasTenant could not be updated [ABP Framework]


I want to add a new property into a new column of the SaasTenants using ABP Commercial (front end is Angular). For so far I've added a EF Core mapping (see code below), created a migrations and updated the database.

ObjectExtensionManager.Instance.MapEfCoreProperty<Tenant, string>(
    TenantExtraPropetiesName.newProp,
    (entityBuilder, propertyBuilder) =>
    {
        propertyBuilder
            .IsRequired()
            .HasMaxLength(10)
            .HasColumnName(TenantExtraPropetiesName.newProp);
    }
);

This property must be edited into the SaaS tenant create form as an additional field. I'm using this code for it.

import { ePropType, FormProp, FormPropList, } from '@abp/ng.theme.shared/extensions';
import { eSaasComponents, SaasCreateFormPropContributors } from '@volo/abp.ng.saas';
import { SaasTenantDto } from '@volo/abp.ng.saas/lib/proxy/host/dtos';

// Additional actions for tenant management.

const newCreateFormProp = new FormProp<SaasTenantDto>({
    name: 'newCreateFormProp',
    type: ePropType.String,
    displayName: '::newCreateFormProp'
});

export function newCreateFromPropContributor(actionList: FormPropList<SaasTenantDto>): void {
    actionList.addTail(newCreateFormProp);
}

export const tenantEntityCreateFormPropContributors: SaasCreateFormPropContributors = {
    [eSaasComponents.Tenants]: [
        newCreateFromPropContributor
    ]
};

and linked it into the AppRoutingModule as follow:

// Removed some lines.
{
    path: 'saas',
    loadChildren: () => import('@volo/abp.ng.saas').then(m => m.SaasModule.forLazy({
        createFormPropContributors: tenantEntityCreateFormPropContributors
    }))
},

The problem now is when I click on Save inside the New tenant modal, the newProp will be an empty string. My guess is that the SaasTenantCreateDto not correctly maps to SaaSTenant. So how could I do it?


Solution

  • After searching for a while, I've found next solution to fix my problem. First I needed to chain this method to ObjectExtensionManager.Instance.MapEfCoreProperty

    .AddOrUpdateProperty<string>(
        new Type[]
        {
            typeof(SaasTenantDto),
            typeof(SaasTenantCreateDto)
        },
        TenantExtraPropetiesName.newProp
    );
    

    Inside my newCreateFormProp I need to add the property isExtra with value true.

    const newCreateFormProp = new FormProp<SaasTenantDto>({
        name: 'newCreateFormProp',
        type: ePropType.String,
        displayName: '::newCreateFormProp'
        isExtra: true
    });
    

    Both actions did solve my issue.