Skip to content

Commit

Permalink
Allow MapEnum() without an enum name
Browse files Browse the repository at this point in the history
Closes #3178
  • Loading branch information
roji committed Nov 14, 2024
1 parent a4d67a1 commit 2f86c15
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/EFCore.PG/Infrastructure/Internal/EnumDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public sealed class EnumDefinition : IEquatable<EnumDefinition>
/// </summary>
public EnumDefinition(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] Type clrType,
string name,
string? name,
string? schema,
INpgsqlNameTranslator nameTranslator)
{
Expand All @@ -80,7 +80,7 @@ public EnumDefinition(
throw new ArgumentException($"Enum type mappings require a CLR enum. {clrType.FullName} is not an enum.");
}

StoreTypeName = name;
StoreTypeName = name ?? nameTranslator.TranslateTypeName(clrType.Name);
StoreTypeSchema = schema;
ClrType = clrType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public virtual NpgsqlOptionsExtension WithUserRangeDefinition(
/// </summary>
public virtual NpgsqlOptionsExtension WithEnumMapping(
Type clrType,
string enumName,
string? enumName,
string? schemaName,
INpgsqlNameTranslator? nameTranslator)
{
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.PG/Infrastructure/NpgsqlDbContextOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public virtual NpgsqlDbContextOptionsBuilder MapRange(
/// <param name="schemaName">The name of the PostgreSQL schema in which the range is defined.</param>
/// <param name="nameTranslator">The name translator used to map enum value names to PostgreSQL enum values.</param>
public virtual NpgsqlDbContextOptionsBuilder MapEnum<T>(
string enumName,
string? enumName = null,
string? schemaName = null,
INpgsqlNameTranslator? nameTranslator = null)
where T : struct, Enum
Expand All @@ -136,7 +136,7 @@ public virtual NpgsqlDbContextOptionsBuilder MapEnum<T>(
/// <param name="nameTranslator">The name translator used to map enum value names to PostgreSQL enum values.</param>
public virtual NpgsqlDbContextOptionsBuilder MapEnum(
Type clrType,
string enumName,
string? enumName = null,
string? schemaName = null,
INpgsqlNameTranslator? nameTranslator = null)
=> WithOption(e => e.WithEnumMapping(clrType, enumName, schemaName, nameTranslator));
Expand Down

0 comments on commit 2f86c15

Please sign in to comment.