如何将abp db表名称更新为MySql约定,例如“ abp_user_role”

时间:2019-01-08 05:06:57

标签: mysql aspnetboilerplate

我正在尝试将ABP模板项目的数据库表名称转换为MySql约定(例如“ abp_user_role”),但对于AbpRoleBase,AbpTenantBase,AbpUserBase失败,其他都很好。

以下是我在数据库上下文中的代码:

    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)OrElse(Convert(e,ISoftDelete).IsDeleted!= value(Test.EntityFrameworkCore.TestDbContext).IsSoftDeleteFilterEnabled)) '承租人'。过滤器只能应用于层次结构中的根实体类型。

1 个答案:

答案 0 :(得分:0)

更正一个:

   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"));
    }