Open Closed

efcore bool,oracle 19c not boolean type, abp vnext oracle bool type error #9453


User avatar
0
heshengli created
  • Exception message and full stack trace:
  • Steps to reproduce the issue: Script-DbContext ef core 方法 是否只能是否这个方式,有通用解决方法么

7 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent

    Oracle 数据库(包括 19c)本身并不支持原生的 BOOLEAN 类型,EF Core 在生成迁移脚本时会直接映射为 BOOLEAN,导致如你截图所示的错误。你当前用的 .HasConversion<int>() 方式(将 bool 转为 int 0/1)是主流且推荐的做法。

    ABP 官方和 EF Core 社区都没有更“自动化”的通用方案,建议如下:

    1. 保持你现在的写法:

      builder.Entity<BackgroundJobRecord>()
          .Property(u => u.IsAbandoned)
          .HasConversion<int>(); // bool 映射为 int (0/1)
      

      这样迁移脚本会生成 NUMBER(1) 字段,兼容 Oracle。

    2. 如果有多个 bool 字段,可以写一个扩展方法批量处理,或在基类/通用配置中统一加上。

    3. 迁移脚本生成后,务必检查是否有 BOOLEAN 类型,手动改为 NUMBER(1) 或 tinyint。

    4. 参考官方文档说明:

      • https://abp.io/docs/latest/framework/data/entity-framework-core/oracle-devart

    结论:EF Core + Oracle 下,bool 字段只能用 .HasConversion<int>() 或手动映射为 NUMBER(1)。没有更自动的通用方案,这是 Oracle 的限制。

    Sources:

    • https://abp.io/docs/latest/framework/data/entity-framework-core/oracle-devart

    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

  • User Avatar
    0
    heshengli created

    使用的Oracle (Official)

  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    Hello 👋,

    This issue does not seem to be related to ABP. However, I have searched a bit and unfortunately there is no other solution as far as I can see. See more: https://stackoverflow.com/a/3726846/9922629

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    EF Core 有一些action 你可以自定义它们来为所有实体增加一些配置

    请参考 https://abp.io/docs/latest/framework/data/entity-framework-core#abpdbcontextoptions

    反射判断属性类型并配置它们。

    https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs#L121-L140

    Configure<AbpDbContextOptions>(options =>
    {
        options.ConfigureDefaultConvention((dbContext, builder) =>
        {
            // This action is called for ConfigureConventions method of all DbContexts.
        });
        options.ConfigureConventions<YourDbContext>((dbContext, builder) =>
        {
            // This action is called for ConfigureConventions method of specific DbContext.
        });
        options.ConfigureDefaultOnModelCreating((dbContext, builder) =>
        {
            // This action is called for OnModelCreating method of all DbContexts.
        });
        options.ConfigureOnModelCreating<YourDbContext>((dbContext, builder) =>
        {
            // This action is called for OnModelCreating method of specific DbContext.
        });
    });
    
  • User Avatar
    0
    heshengli created

    protected override void ConfigureConventions(ModelConfigurationBuilder builder) { builder.Properties<bool>().HaveConversion<BoolToZeroOneConverter<int>>(); builder.Properties<bool?>().HaveConversion<BoolToZeroOneConverter<int?>>(); } efcore 自带了一堆方法

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    好的.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Solution: UseOracleSQLCompatibility(OracleSQLCompatibility.DatabaseVersion19)

Learn More, Pay Less
33% OFF
All Trainings!
Get Your Deal
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.0.0-preview. Updated on September 10, 2025, 06:30