如何将abp db表名更新为mysql约定,如“abp\u user\u role”

dly7yett  于 2021-06-15  发布在  Mysql
关注(0)|答案(1)|浏览(360)

我正在尝试将abp模板项目的db表名转换为mysql约定,比如'abp\u user\u role',但是对于abprolebase、abptenantbase、abpuserbase都失败了,其他的都很好。
以下是我在db上下文中的代码:

protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        UpdateAbpTableNamesForMySqlConvention(modelBuilder);

        modelBuilder.Entity<TestEntity>(entity =>
        {
            entity.HasKey(e => new { e.Id });

            entity.ToTable("test_entity");
        });

    }

    private void UpdateAbpTableNamesForMySqlConvention(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<AuditLog>(e => { e.ToTable("abp_audit_log"); });
        modelBuilder.Entity<BackgroundJobInfo>(e => { e.ToTable("abp_background_job"); });
        modelBuilder.Entity<Edition>(e => { e.ToTable("abp_edition"); });
        modelBuilder.Entity<EntityChange>(e => { e.ToTable("abp_entity_change"); });
        modelBuilder.Entity<EntityChangeSet>(e => { e.ToTable("abp_entity_change_set"); });
        modelBuilder.Entity<EntityPropertyChange>(e => { e.ToTable("abp_entity_property_change"); });
        modelBuilder.Entity<FeatureSetting>(e => { e.ToTable("abp_feature"); });
        modelBuilder.Entity<ApplicationLanguage>(e => { e.ToTable("abp_language"); });
        modelBuilder.Entity<ApplicationLanguageText>(e => { e.ToTable("abp_language_text"); });
        modelBuilder.Entity<NotificationInfo>(e => { e.ToTable("abp_notification"); });
        modelBuilder.Entity<NotificationSubscriptionInfo>(e => { e.ToTable("abp_notification_subscription"); });
        modelBuilder.Entity<OrganizationUnit>(e => e.ToTable("abp_organization_unit"));
        modelBuilder.Entity<PermissionSetting>(e => e.ToTable("abp_permission_setting"));
        modelBuilder.Entity<RoleClaim>(e => e.ToTable("abp_role_claim"));
        //modelBuilder.Entity<AbpRoleBase>(e => e.ToTable("abp_role"));
        modelBuilder.Entity<Setting>(e => e.ToTable("abp_setting"));
        modelBuilder.Entity<TenantNotificationInfo>(e => e.ToTable("abp_tenant_notification"));
        //modelBuilder.Entity<AbpTenantBase>(e => e.ToTable("abp_tenant"));
        modelBuilder.Entity<UserAccount>(e => e.ToTable("abp_user_account"));
        modelBuilder.Entity<UserClaim>(e => e.ToTable("abp_user_claim"));
        modelBuilder.Entity<UserLoginAttempt>(e => e.ToTable("abp_user_login_attempt"));
        modelBuilder.Entity<UserLogin>(e => e.ToTable("abp_user_login"));
        modelBuilder.Entity<UserNotificationInfo>(e => e.ToTable("abp_user_notification"));
        modelBuilder.Entity<UserOrganizationUnit>(e => e.ToTable("abp_user_organization_unit"));
        modelBuilder.Entity<UserRole>(e => e.ToTable("abp_user_role"));
        //modelBuilder.Entity<AbpUserBase>(e => e.ToTable("abp_user"));
        modelBuilder.Entity<UserToken>(e => e.ToTable("abp_user_token"));

}
出现错误:筛选器表达式'e=>(not(convert(e,isoftdelete).isdeleted)或lse(convert(e,isoftdelete).isdeleted!=不能为实体类型“tenant”指定值(test.entityframeworkcore.testdbcontext).issoftdeletefilterenabled))。筛选器只能应用于层次结构中的根实体类型。

sqougxex

sqougxex1#

正确答案:

private void UpdateAbpTableNamesForMySqlConvention(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<AuditLog>(e => { e.ToTable("abp_audit_log"); });
        modelBuilder.Entity<BackgroundJobInfo>(e => { e.ToTable("abp_background_job"); });
        modelBuilder.Entity<Edition>(e => { e.ToTable("abp_edition"); });
        modelBuilder.Entity<EntityChange>(e => { e.ToTable("abp_entity_change"); });
        modelBuilder.Entity<EntityChangeSet>(e => { e.ToTable("abp_entity_change_set"); });
        modelBuilder.Entity<EntityPropertyChange>(e => { e.ToTable("abp_entity_property_change"); });
        modelBuilder.Entity<FeatureSetting>(e => { e.ToTable("abp_feature"); });
        modelBuilder.Entity<ApplicationLanguage>(e => { e.ToTable("abp_language"); });
        modelBuilder.Entity<ApplicationLanguageText>(e => { e.ToTable("abp_language_text"); });
        modelBuilder.Entity<NotificationInfo>(e => { e.ToTable("abp_notification"); });
        modelBuilder.Entity<NotificationSubscriptionInfo>(e => { e.ToTable("abp_notification_subscription"); });
        modelBuilder.Entity<OrganizationUnit>(e => e.ToTable("abp_organization_unit"));
        modelBuilder.Entity<PermissionSetting>(e => e.ToTable("abp_permission_setting"));
        modelBuilder.Entity<RoleClaim>(e => e.ToTable("abp_role_claim"));
        modelBuilder.Entity<Role>(e => e.ToTable("abp_role"));
        modelBuilder.Entity<Setting>(e => e.ToTable("abp_setting"));
        modelBuilder.Entity<TenantNotificationInfo>(e => e.ToTable("abp_tenant_notification"));
        modelBuilder.Entity<Tenant>(e => e.ToTable("abp_tenant"));
        modelBuilder.Entity<UserAccount>(e => e.ToTable("abp_user_account"));
        modelBuilder.Entity<UserClaim>(e => e.ToTable("abp_user_claim"));
        modelBuilder.Entity<UserLoginAttempt>(e => e.ToTable("abp_user_login_attempt"));
        modelBuilder.Entity<UserLogin>(e => e.ToTable("abp_user_login"));
        modelBuilder.Entity<UserNotificationInfo>(e => e.ToTable("abp_user_notification"));
        modelBuilder.Entity<UserOrganizationUnit>(e => e.ToTable("abp_user_organization_unit"));
        modelBuilder.Entity<UserRole>(e => e.ToTable("abp_user_role"));
        modelBuilder.Entity<User>(e => e.ToTable("abp_user"));
        modelBuilder.Entity<UserToken>(e => e.ToTable("abp_user_token"));
    }

相关问题