0

I'm building a .NET Aspire-based application using PostgreSQL with Entity Framework Core. I’m registering my DbContext like this as I am using Aspire.Npgsql.EntityFrameworkCore.PostgreSQL package:

builder.AddNpgsqlDbContext<AppDbContext>(
    "ConnectionName",
    configureDbContextOptions: b =>
    {
        // remove this after testing
        b.EnableSensitiveDataLogging(true);
    });

I want to customize the name and schema of the EF Core migrations history table (which defaults to __EFMigrationsHistory). I know that if I was using EF Core methods directly to register the DbContext you can do something like:

services.AddDbContext<AppDbContext>(
        options =>
        {
            options
                .UseNpgsql(
                    "ConnectionString",
                    x => x.MigrationsHistoryTable("__ef_migrations_history"));
        });

I am not seeing such an option if I am doing things the Aspire way. Has anyone successfully configured a custom migrations history table name with AddNpgsqlDbContext<>() in a .NET Aspire project? Am I missing something in the setup?

3
  • Can't you just do b.UseNpgsql(x => { x.MigrationsHistoryTable("my-table-name"); }); alongside the EnableSensitiveDataLogging line? Commented Apr 13 at 19:50
  • @DavidG I could. But AddNpgsqlDbContext<AppDbContext> code is already calling UseNpgsql under the hood. I wanted to avoid the redundancy. Commented Apr 14 at 0:41
  • @DavidG I think the option you provided is the only available way to do this as of now. If you could provide it as an answer I can mark accepted. Commented Apr 14 at 2:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.