Using MapEnum doesn't seem to work properly
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 25/100
調査の方向性
Start by reading the issue's MapEnum configuration and the referenced issue #3390, then investigate how enum mappings supplied through UseNpgsql relate to the NpgsqlDataSourceBuilder setup. The issue provides a failing read and an exception; done means identifying why the Sex enum is treated as unmapped and documenting or correcting the behavior.
索引モデルが issue の本文から書いたものです。
説明
I all,
I'm not sure wether I'm doing something wrong or this functionality is a bit broken, but I'm setting up my enums like this:
var dataSourceBuilder = new NpgsqlDataSourceBuilder(configuration.ConnectionString);
dataSourceBuilder.EnableDynamicJson();
var dataSource = dataSourceBuilder.Build();
services.AddDbContext<DCMContext>(options => options.UseNpgsql(dataSource,
o => {
o.MapEnum<DeviceType>();
o.MapEnum<DispatchStatus>();
o.MapEnum<DriverStatus>();
o.MapEnum<FuelType>();
o.MapEnum<PaymentStatus>();
o.MapEnum<PaymentType>();
o.MapEnum<RateType>();
o.MapEnum<SettingRight>();
o.MapEnum<SettingType>();
o.MapEnum<Sex>();
o.MapEnum<TransferStatus>();
o.MapEnum<TripCancelReason>();
o.MapEnum<TripScope>();
o.MapEnum<TripStatus>();
}));
And create a migration which results in this:
migrationBuilder.AlterDatabase()
.Annotation("Npgsql:Enum:device_type", "android,ios")
.Annotation("Npgsql:Enum:dispatch_status", "accepted,automatic,canceled,pending,rejected,timeout")
.Annotation("Npgsql:Enum:driver_status", "available,on_break,on_shift,unavailable")
.Annotation("Npgsql:Enum:fuel_type", "cng,diesel,electric,hydrogen,lpg,petrol,unknown")
.Annotation("Npgsql:Enum:payment_status", "awaiting_method,completed,failed,pending,processing,refunded,requires_manual_intervention")
.Annotation("Npgsql:Enum:payment_type", "bank_transfer,cash,credit_card,debit_card,invoice,online_payment")
.Annotation("Npgsql:Enum:rate_type", "distance,starting_rate,time")
.Annotation("Npgsql:Enum:setting_right", "admin,self")
.Annotation("Npgsql:Enum:setting_type", "base64,bool,date,date_time,duration,float,integer,string,time")
.Annotation("Npgsql:Enum:sex", "female,male,other,unknown")
.Annotation("Npgsql:Enum:transfer_status", "canceled,completed,failed,in_progress,pending")
.Annotation("Npgsql:Enum:trip_cancel_reason", "client_cancels,client_gone,contractor_unknown,date_time_wrong,double_booked,van_required")
.Annotation("Npgsql:Enum:trip_scope", "combined,return,standard")
.Annotation("Npgsql:Enum:trip_status", "accepted,canceled,canceled_requested,completed,declined,in_progress,in_transit,new,no_show,no_show_requested");
And the model snapshot:
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "device_type", new[] { "android", "ios" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "dispatch_status", new[] { "accepted", "automatic", "canceled", "pending", "rejected", "timeout" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "driver_status", new[] { "available", "on_break", "on_shift", "unavailable" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "fuel_type", new[] { "cng", "diesel", "electric", "hydrogen", "lpg", "petrol", "unknown" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "payment_status", new[] { "awaiting_method", "completed", "failed", "pending", "processing", "refunded", "requires_manual_intervention" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "payment_type", new[] { "bank_transfer", "cash", "credit_card", "debit_card", "invoice", "online_payment" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "rate_type", new[] { "distance", "starting_rate", "time" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "setting_right", new[] { "admin", "self" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "setting_type", new[] { "base64", "bool", "date", "date_time", "duration", "float", "integer", "string", "time" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "sex", new[] { "female", "male", "other", "unknown" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "transfer_status", new[] { "canceled", "completed", "failed", "in_progress", "pending" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "trip_cancel_reason", new[] { "client_cancels", "client_gone", "contractor_unknown", "date_time_wrong", "double_booked", "van_required" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "trip_scope", new[] { "combined", "return", "standard" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "trip_status", new[] { "accepted", "canceled", "canceled_requested", "completed", "declined", "in_progress", "in_transit", "new", "no_show", "no_show_requested" });
...
b1.Property<Sex>("Sex")
.HasColumnType("sex");
Now I'm getting this exception when retrieving data from the database:
System.InvalidCastException: Reading as 'DCM.Entities.Enums.Sex' is not supported for fields having DataTypeName 'public.sex'
---> System.NotSupportedException: Reading and writing unmapped enums requires an explicit opt-in; call 'EnableUnmappedTypes' on 'NpgsqlDataSourceBuilder' or NpgsqlConnection.GlobalTypeMapper....
And this is how the enum looks like:
public enum Sex
{
Unknown,
Male,
Female,
Other
}
As you can see the order is different, but I thought by reading through issue #3390 that it shouldn't matter. But still I'm getting above mentioned exception. Could somebody help me out?
Thank you
- 主要言語
- C#
- スター
- 1.8k
- フォーク
- 268
- 平均マージ
- 2時間 35分
- マージ済み PR(30日)
- 136
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
npgsql/efcore.pg のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
NTS: the M ordinate is dropped from geometry SQL literals and from geometries stored in JSON対応中かも @Ahmed7991 が 5 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
npgsql/efcore.pg#4093 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
`TimeSpan`/`Duration` component members: negative values are floored, and intervals computed in SQL are read field by field対応中かも @jeremy-morren が 11 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
Numeric storage parameters are formatted with the current culture, so migrations emit 0,01 instead of 0.01対応中かも @Sorbitol が 12 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 30/100
メンテナーはふだん 1 日以内に返信
-
`Contains` on a JSON primitive collection compares JSON text, so `DateTime` and `TimeOnly` items never match対応中かも @Mr444-dev が 7 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
npgsql/efcore.pg#4099 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
npgsql/efcore.pg の issue をすべて見る
似ている issue
-
Issue-Bug Needs-Triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
JiaFeiMiao-K-Cat/DiscImageStudio#281 ·
メンテナーはふだん 1 日以内に返信
-
area/access-management Frontend onboarding candidate :handshake:
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
Altinn/altinn-auth#4941 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
aws/aws-sdk-net#4586 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
Kryptos-FR/MarkView.Avalonia#269 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信