Base solution for your next web application
Open Closed

Custom Table Names are not working with latest version #6777


User avatar
0
muleso created

i want to add AbpOrganizationUnitRoles table to a custom table, advice

using Abp.Application.Editions;
using Abp.Application.Features;
using Abp.Auditing;
using Abp.Authorization;
using Abp.Authorization.Roles;
using Abp.Authorization.Users;
using Abp.BackgroundJobs;
using Abp.Configuration;
using Abp.Localization;
using Abp.MultiTenancy;
using Abp.Notifications;
using Abp.Organizations;
using Microsoft.EntityFrameworkCore;

namespace Abp.Zero.EntityFrameworkCore
{
    /// <summary>
    /// Extension methods for <see cref="DbModelBuilder"/>.
    /// </summary>
    public static class AbpZeroDbModelBuilderExtensions
    {
        /// <summary>
        /// Changes prefix for ABP tables (which is "Abp" by default).
        /// Can be null/empty string to clear the prefix.
        /// </summary>
        /// <typeparam name="TTenant">The type of the tenant entity.</typeparam>
        /// <typeparam name="TRole">The type of the role entity.</typeparam>
        /// <typeparam name="TUser">The type of the user entity.</typeparam>
        /// <param name="modelBuilder">Model builder.</param>
        /// <param name="prefix">Table prefix, or null to clear prefix.</param>
        public static void ChangeAbpTablePrefix0<TTenant, TRole, TUser>(this ModelBuilder modelBuilder, string prefix, string schemaName = null)
            where TTenant : AbpTenant<TUser>
            where TRole : AbpRole<TUser>
            where TUser : AbpUser<TUser>
        {
            prefix = prefix ?? "";

            SetTableName<AuditLog>(modelBuilder, prefix + "30", schemaName);
            SetTableName<BackgroundJobInfo>(modelBuilder, prefix + "31", schemaName);
            SetTableName<Edition>(modelBuilder, prefix + "32", schemaName);
            SetTableName<FeatureSetting>(modelBuilder, prefix + "33", schemaName);
            SetTableName<TenantFeatureSetting>(modelBuilder, prefix + "34", schemaName);
            SetTableName<EditionFeatureSetting>(modelBuilder, prefix + "35", schemaName);
            SetTableName<ApplicationLanguage>(modelBuilder, prefix + "36", schemaName);
            SetTableName<ApplicationLanguageText>(modelBuilder, prefix + "37", schemaName);
            SetTableName<NotificationInfo>(modelBuilder, prefix + "38", schemaName);
            SetTableName<NotificationSubscriptionInfo>(modelBuilder, prefix + "39", schemaName);
            SetTableName<OrganizationUnit>(modelBuilder, prefix + "40", schemaName);
            SetTableName<PermissionSetting>(modelBuilder, prefix + "41", schemaName);
            SetTableName<RolePermissionSetting>(modelBuilder, prefix + "42", schemaName);
            SetTableName<UserPermissionSetting>(modelBuilder, prefix + "43", schemaName);
            SetTableName<TRole>(modelBuilder, prefix + "44", schemaName);
            SetTableName<Setting>(modelBuilder, prefix + "45", schemaName);
            SetTableName<TTenant>(modelBuilder, prefix + "46", schemaName);
            SetTableName<UserLogin>(modelBuilder, prefix + "47", schemaName);
            SetTableName<UserLoginAttempt>(modelBuilder, prefix + "48", schemaName);
            SetTableName<TenantNotificationInfo>(modelBuilder, prefix + "49", schemaName);
            SetTableName<UserNotificationInfo>(modelBuilder, prefix + "50", schemaName);
            SetTableName<UserOrganizationUnit>(modelBuilder, prefix + "51", schemaName);
            SetTableName<UserRole>(modelBuilder, prefix + "52", schemaName);
            SetTableName<TUser>(modelBuilder, prefix + "53", schemaName);
            SetTableName<UserAccount>(modelBuilder, prefix + "54", schemaName);
            SetTableName<UserClaim>(modelBuilder, prefix + "55", schemaName);

            //SetTableName<>(modelBuilder, prefix + "55", schemaName);
        }

        private static void SetTableName<TEntity>(ModelBuilder modelBuilder, string tableName, string schemaName)
            where TEntity : class
        {
            if (schemaName == null)
            {
                modelBuilder.Entity<TEntity>().ToTable(tableName);
            }
            else
            {
                modelBuilder.Entity<TEntity>().ToTable(tableName, schemaName);
            }
        }
    }
}

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

    Please share your DbContext code.

  • User Avatar
    0
    muleso created

    Hello,

    I think, you didn't get my question, i want to add a new table AbpOrganizationUnitRoles to above class, this new table you added in the latest version, it wasnt there before

  • User Avatar
    0
    muleso created

    Hello,

    That worked and tables created, but when i run migration, am getting this error , i was getting it before.

  • User Avatar
    0
    ismcagdas created
    Support Team