From b3d9e9568d614e478247dcdc9ab853a842eb282d Mon Sep 17 00:00:00 2001 From: Rubens Cordeiro Date: Sat, 8 Mar 2025 16:03:10 +0100 Subject: [PATCH] Improve error message when duplicate enum definitions are registered. --- .../Storage/Internal/NpgsqlTypeMappingSource.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/EFCore.PG/Storage/Internal/NpgsqlTypeMappingSource.cs b/src/EFCore.PG/Storage/Internal/NpgsqlTypeMappingSource.cs index e5719e76e..1a4a8b04c 100644 --- a/src/EFCore.PG/Storage/Internal/NpgsqlTypeMappingSource.cs +++ b/src/EFCore.PG/Storage/Internal/NpgsqlTypeMappingSource.cs @@ -785,7 +785,14 @@ static Type FindTypeToInstantiate(Type collectionType, Type elementType) EnumDefinition? enumDefinition; if (storeType is null) { - enumDefinition = _enumDefinitions.SingleOrDefault(m => m.ClrType == clrType); + var matches = _enumDefinitions.Where(m => m.ClrType == clrType).ToList(); + if (matches.Count > 1) + { + throw new InvalidOperationException( + $"Multiple enum definitions registered for CLR type '{clrType?.FullName}'. "); + } + + enumDefinition = matches.FirstOrDefault(); if (enumDefinition is null) {