Difference between NpgsqlDataSourceBuilder.EnableDynamicJson and NpgsqlConnection.GlobalTypeMapper.EnableDynamicJson()

Offen
#3,615 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
25/100
Issue-Typ
Bug
Klarheit
Muss geklärt werden
Aktivitätsstatus
Veraltet
Tech-Stack
csharp, postgresql
Bereich
databases

Rechercherichtung

No source files or tests are named. Start by reading the Npgsql EF Core provider guidance for NpgsqlDataSourceBuilder.EnableDynamicJson, ConfigureDataSource, and UseNpgsql; compare how each configuration is applied to both DbContexts. Done means identifying why the shown setups still raise the exception and establishing a non-deprecated configuration that works for both contexts.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Hello, we are migrating from the older version to a newer version of both npgsql and EF Core. As we have so many jsonb columns throughout the application, we have chosen to EnableDynamicJson, but we couldn't get rid of the exceptions that suggest enabling dynamic json serialization. We have two DbContexts in our app. At first, I tried to fix the issue by passing the NpgsqlDataSource manually like below, doing it separately for both contexts:

 var dataSourceBuilder = new NpgsqlDataSourceBuilder(config.ConnectionStrings.AppDb);
            dataSourceBuilder.EnableDynamicJson();
            
            builder.UseNpgsql(dataSourceBuilder.Build(), options =>
                   {
                       options.MigrationsAssembly(asmName);
                   })


// repeat for the other datasource

This didn't work. Also tried below separately :

    builder.UseNpgsql(config.ConnectionStrings.AppDb, options =>
                   {
                       options.MigrationsAssembly(asmName);
                       options.ConfigureDataSource(ds => ds.EnableDynamicJson());
                   })

// repeat for the other datasource

Also tried to inject NpgsqlDataSource via DI like the below :

        services.AddNpgsqlDataSource(config.ConnectionStrings.ScrapDb, builder=> builder.EnableDynamicJson(),
                                     serviceKey: "ScrapDataSource");
        services.AddNpgsqlDataSource(config.ConnectionStrings.AppDb, builder=> builder.EnableDynamicJson(),
                                     serviceKey: "AppDataSource");

      builder.UseNpgsql(sp.GetKeyedService<NpgsqlDataSource>("AppDataSource"),
                              options => options.MigrationsAssembly(asmName))
                                                )
// repeat for the other datasource

The only solution that has worked so far is to use NpgsqlConnection.GlobalTypeMapper.EnableDynamicJson(). (Which we want to avoid as it is deprecated.) I don't know what I am currently doing wrong, or if it is somehow related to having multiple DbContexts.

I also don't have any OnConfiguring overrides in my DbContexts. They are just accept DbContextOptions like the below:

    public partial class AppDbContext : DbContext
    {
        public AppDbContext()
        {
        }

        public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
        {
        }
 
        // dbsets here
    }

    public class ScrapDbContext : DbContext
    {
        public ScrapDbContext()
        {
        }

        public ScrapDbContext(DbContextOptions<ScrapDbContext> options) : base(options)
        {
        }

     // dbsets here
   }
Vorherrschende Sprache
C#
Sterne
1.8k
Forks
268
Ø Merge
2 Std. 35 Min.
Gemergte PRs (30 T.)
136

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus npgsql/efcore.pg

Alle Issues in npgsql/efcore.pg

Ähnliche Issues

Weitere Issues zu C#

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.