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

オープン
#3,615 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
csharp, postgresql
領域
databases

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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
   }
主要言語
C#
スター
1.8k
フォーク
268
平均マージ
2時間 35分
マージ済み PR(30日)
136

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

npgsql/efcore.pg のほかの issue

npgsql/efcore.pg の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。