Open Closed

Low-Code: PostgreSQL EF Core query fails due to incompatible NpgsqlSqlGenerationHelper type #10968


User avatar
0
JackZhang2026 created
  • Exception message and full stack trace:
  • System.InvalidCastException: Unable to cast object of type 'Volo.Abp.LowCode.EntityFrameworkCore.JsonPaths.WordJsonPathElementSqlGenerationHelper' to type 'Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper'.

at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync[TSource](IAsyncEnumerable1 asyncEnumerable, CancellationToken cancellationToken) at Volo.Abp.Identity.EntityFrameworkCore.EfCoreIdentityUserRepository.FindByNormalizedUserNameAsync(String normalizedUserName, Boolean includeDetails, CancellationToken cancellationToken) at Npgsql.EntityFrameworkCore.PostgreSQL.Query.Internal.NpgsqlQuerySqlGenerator..ctor(QuerySqlGeneratorDependencies dependencies, IRelationalTypeMappingSource typeMappingSource, Boolean reverseNullOrderingEnabled, Version postgresVersion) at Npgsql.EntityFrameworkCore.PostgreSQL.Query.Internal.NpgsqlQuerySqlGeneratorFactory.Create() at Microsoft.EntityFrameworkCore.Query.Internal.RelationalCommandCache.GetRelationalCommandTemplate(Dictionary2 parameters) at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken) at Volo.Abp.Identity.IdentityDataSeeder.SeedAsync(String adminEmail, String adminPassword, Nullable1 tenantId, String adminUserName) at Volo.Abp.Identity.UserSharing.UserSharingIdentityDataSeeder.SeedAsync(String adminEmail, String adminPassword, Nullable`1 tenantId, String adminUserName)

  • Steps to reproduce the issue:
  1. Create an ABP solution using ABP Studio.
  2. Configure PostgreSQL as the database provider.
  3. Add or enable the ABP Low-Code module.
  4. . Initialize the database and execute the Identity data seeding process.
  5. The exception occurs when IdentityDataSeeder calls FindByNormalizedUserNameAsync.
Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

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

    Hi,

    In 11.0.0 the Low-Code module wraps the EF Core ISqlGenerationHelper for every DbContext that implements IDbContextWithDynamicEntities. The PostgreSQL provider casts this helper to its own NpgsqlSqlGenerationHelper when it builds a query, so every query on your main DbContext fails, not only the data seeding.

    You can use this workaround for now. Add this class to your EntityFrameworkCore project:

    using Microsoft.EntityFrameworkCore.Storage;
    using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal;
    using Volo.Abp.LowCode.EntityFrameworkCore.JsonPaths;
    
    #pragma warning disable EF1001
    
    public class LowCodeNpgsqlSqlGenerationHelper : NpgsqlSqlGenerationHelper
    {
        public LowCodeNpgsqlSqlGenerationHelper(RelationalSqlGenerationHelperDependencies dependencies)
            : base(dependencies)
        {
        }
    
        public override string DelimitJsonPathElement(string pathElement)
        {
            return WordJsonPathElementSqlGenerationHelper.IsWord(pathElement)
                ? pathElement
                : base.DelimitJsonPathElement(pathElement);
        }
    }
    

    Then add this to the ConfigureServices method of your *EntityFrameworkCoreModule:

    Configure<AbpDbContextOptions>(options =>
    {
        options.ConfigureDefaultOnConfiguring((dbContext, optionsBuilder) =>
        {
            if (dbContext is IDbContextWithDynamicEntities)
            {
                optionsBuilder.ReplaceService<ISqlGenerationHelper, LowCodeNpgsqlSqlGenerationHelper>();
            }
        });
    });
    

    We'll fix this in the next patch release. You can remove the workaround after upgrading. Your ticket has been refunded.

    Thanks

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    JackZhang2026 created

    Thanks for the explanation and workaround. I can try this workaround. Just to confirm, is this a known bug in ABP 11.0.0? Is there a plan to fix it in a future release? If so, could you let us know which version is expected to include the fix?

    Thanks again for your help!

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Hi,

    Yes. The fix is already merged and will be included in 11.0.1. I don't have an exact release date yet, so please use the workaround until then.

    Thanks

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    JackZhang2026 created

    Thanks for the update!

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v11.1.0-preview. Updated on November 20, 2026, 13:33
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.