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

Aberta
#3,615 2 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
25/100
Tipo de issue
Bug
Clareza
Precisa de esclarecimento
Status de atividade
Estagnada
Stack de tecnologia
csharp, postgresql
Domínio
databases

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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
   }
Linguagem predominante
C#
Estrelas
1.8k
Forks
268
Merge médio
2h 35min
PRs com merge (30d)
136

Preparar o ambiente

Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de npgsql/efcore.pg

Todas as issues de npgsql/efcore.pg

Issues semelhantes

Mais issues de C#

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.