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

Abierto
#3,615 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
csharp, postgresql
Área
databases

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
   }
Lenguaje dominante
C#
Estrellas
1.8k
Forks
268
Merge medio
2 h 35 min
PR fusionados (30 d)
136

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de npgsql/efcore.pg

Todos los issues de npgsql/efcore.pg

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.