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

Ouverte
#3,615 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
25/100
Type d'issue
Bug
Clarté
À clarifier
Activité
À l'abandon
Stack technique
csharp, postgresql
Domaine
databases

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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
   }
Langage dominant
C#
Étoiles
1.8k
Forks
268
Merge moyen
2 h 35 min
PR mergées (30 j)
136

Préparer son environnement

Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de npgsql/efcore.pg

Toutes les issues de npgsql/efcore.pg

Issues similaires

Plus d'issues C#

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.