diff --git a/src/EFCore/Storage/Json/JsonSignedEnumReaderWriter.cs b/src/EFCore/Storage/Json/JsonSignedEnumReaderWriter.cs
index bf0651b1188..4870dc7ae2f 100644
--- a/src/EFCore/Storage/Json/JsonSignedEnumReaderWriter.cs
+++ b/src/EFCore/Storage/Json/JsonSignedEnumReaderWriter.cs
@@ -9,6 +9,7 @@ namespace Microsoft.EntityFrameworkCore.Storage.Json;
/// Reads and writes JSON for values backed by a signed integer.
///
public sealed class JsonSignedEnumReaderWriter : JsonValueReaderWriter
+ where TEnum : struct, Enum
{
///
/// The singleton instance of this stateless reader/writer.
diff --git a/src/EFCore/Storage/Json/JsonUnsignedEnumReaderWriter.cs b/src/EFCore/Storage/Json/JsonUnsignedEnumReaderWriter.cs
index a3ff3d9e9fb..a2ee0b607bf 100644
--- a/src/EFCore/Storage/Json/JsonUnsignedEnumReaderWriter.cs
+++ b/src/EFCore/Storage/Json/JsonUnsignedEnumReaderWriter.cs
@@ -9,6 +9,7 @@ namespace Microsoft.EntityFrameworkCore.Storage.Json;
/// Reads and writes JSON for values backed by an unsigned integer.
///
public sealed class JsonUnsignedEnumReaderWriter : JsonValueReaderWriter
+ where TEnum : struct, Enum
{
///
/// The singleton instance of this stateless reader/writer.
diff --git a/src/EFCore/Storage/Json/JsonWarningEnumReaderWriter.cs b/src/EFCore/Storage/Json/JsonWarningEnumReaderWriter.cs
index 1a757576a3e..3e38ae9d11c 100644
--- a/src/EFCore/Storage/Json/JsonWarningEnumReaderWriter.cs
+++ b/src/EFCore/Storage/Json/JsonWarningEnumReaderWriter.cs
@@ -10,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore.Storage.Json;
/// happens, a warning is generated.
///
public sealed class JsonWarningEnumReaderWriter : JsonValueReaderWriter
- where TEnum : struct
+ where TEnum : struct, Enum
{
///
/// The singleton instance of this stateless reader/writer.
diff --git a/src/EFCore/Storage/ValueConversion/EnumToNumberConverter.cs b/src/EFCore/Storage/ValueConversion/EnumToNumberConverter.cs
index 611b3cd9b7e..01c66b0c971 100644
--- a/src/EFCore/Storage/ValueConversion/EnumToNumberConverter.cs
+++ b/src/EFCore/Storage/ValueConversion/EnumToNumberConverter.cs
@@ -10,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore.Storage.ValueConversion;
/// See EF Core value converters for more information and examples.
///
public class EnumToNumberConverter : ValueConverter
- where TEnum : struct
+ where TEnum : struct, Enum
where TNumber : struct
{
// ReSharper disable once StaticMemberInGenericType
diff --git a/src/EFCore/Storage/ValueConversion/EnumToStringConverter.cs b/src/EFCore/Storage/ValueConversion/EnumToStringConverter.cs
index 60f16ed19e0..5deccdbe343 100644
--- a/src/EFCore/Storage/ValueConversion/EnumToStringConverter.cs
+++ b/src/EFCore/Storage/ValueConversion/EnumToStringConverter.cs
@@ -12,7 +12,7 @@ namespace Microsoft.EntityFrameworkCore.Storage.ValueConversion;
/// See EF Core value converters for more information and examples.
///
public class EnumToStringConverter : StringEnumConverter
- where TEnum : struct
+ where TEnum : struct, Enum
{
///
/// Creates a new instance of this converter. This converter does not preserve order.
diff --git a/src/EFCore/Storage/ValueConversion/Internal/StringEnumConverter.cs b/src/EFCore/Storage/ValueConversion/Internal/StringEnumConverter.cs
index 9b86ccc731b..fc2c8ec5703 100644
--- a/src/EFCore/Storage/ValueConversion/Internal/StringEnumConverter.cs
+++ b/src/EFCore/Storage/ValueConversion/Internal/StringEnumConverter.cs
@@ -10,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal;
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
public class StringEnumConverter : ValueConverter
- where TEnum : struct
+ where TEnum : struct, Enum
{
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
diff --git a/src/EFCore/Storage/ValueConversion/StringToEnumConverter.cs b/src/EFCore/Storage/ValueConversion/StringToEnumConverter.cs
index 8d353ea0eab..2761f19bced 100644
--- a/src/EFCore/Storage/ValueConversion/StringToEnumConverter.cs
+++ b/src/EFCore/Storage/ValueConversion/StringToEnumConverter.cs
@@ -12,7 +12,7 @@ namespace Microsoft.EntityFrameworkCore.Storage.ValueConversion;
/// See EF Core value converters for more information and examples.
///
public class StringToEnumConverter : StringEnumConverter
- where TEnum : struct
+ where TEnum : struct, Enum
{
///
/// Creates a new instance of this converter. This converter does not preserve order.
diff --git a/test/EFCore.Tests/Storage/EnumToNumberConverterTest.cs b/test/EFCore.Tests/Storage/EnumToNumberConverterTest.cs
index 77a2491f156..64a432cb1f0 100644
--- a/test/EFCore.Tests/Storage/EnumToNumberConverterTest.cs
+++ b/test/EFCore.Tests/Storage/EnumToNumberConverterTest.cs
@@ -265,26 +265,6 @@ public void Can_convert_ulongs_to_enums()
Assert.Equal(default, converter(0));
}
- [ConditionalFact]
- public void Enum_to_integer_converter_throws_for_bad_types()
- {
- Assert.Equal(
- CoreStrings.ConverterBadType(
- typeof(EnumToNumberConverter).ShortDisplayName(),
- "Guid",
- "enum types"),
- Assert.Throws(
- () => new EnumToNumberConverter()).Message);
-
- Assert.Equal(
- CoreStrings.ConverterBadType(
- typeof(EnumToNumberConverter).ShortDisplayName(),
- "Guid",
- "'int', 'long', 'short', 'byte', 'uint', 'ulong', 'ushort', 'sbyte', 'double', 'float', 'decimal'"),
- Assert.Throws(
- () => new EnumToNumberConverter()).Message);
- }
-
private enum Beatles
{
John = 7,
diff --git a/test/EFCore.Tests/Storage/EnumToStringConverterTest.cs b/test/EFCore.Tests/Storage/EnumToStringConverterTest.cs
index c54501c3c0b..154164debfa 100644
--- a/test/EFCore.Tests/Storage/EnumToStringConverterTest.cs
+++ b/test/EFCore.Tests/Storage/EnumToStringConverterTest.cs
@@ -77,16 +77,6 @@ public void Can_convert_strings_to_enums_object()
Assert.Null(converter(null));
}
- [ConditionalFact]
- public void Enum_to_string_converter_throws_for_bad_types()
- => Assert.Equal(
- CoreStrings.ConverterBadType(
- typeof(StringEnumConverter).ShortDisplayName(),
- "Guid",
- "enum types"),
- Assert.Throws(
- () => new EnumToStringConverter()).Message);
-
private enum Beatles
{
John = 7,
diff --git a/test/EFCore.Tests/Storage/StringToEnumConverterTest.cs b/test/EFCore.Tests/Storage/StringToEnumConverterTest.cs
index 4ea4bef7452..eaeaed6040b 100644
--- a/test/EFCore.Tests/Storage/StringToEnumConverterTest.cs
+++ b/test/EFCore.Tests/Storage/StringToEnumConverterTest.cs
@@ -78,16 +78,6 @@ public void Can_convert_enums_to_strings_object()
Assert.Null(converter(null));
}
- [ConditionalFact]
- public void String_to_enum_converter_throws_for_bad_types()
- => Assert.Equal(
- CoreStrings.ConverterBadType(
- typeof(StringEnumConverter).ShortDisplayName(),
- "Guid",
- "enum types"),
- Assert.Throws(
- () => new StringToEnumConverter()).Message);
-
private enum Beatles
{
John = 7,