A meaningful string as a column value makes a database row easier to read. A string in a database row does not auto-magically convert into meaning in the application layer. The application still has to turn that code into something it understands.
That conversion often spreads. One caller parses an enum name. Another accepts a different spelling. A third substitutes a default. Display names and business rules accumulate in switches and helper methods.
The enum declaration stays small while the decisions around it become harder to find.
I prefer an Enumeration class as an extension of an enum: retain the enum as the definition of the named choices, then give conversion and shared behavior a common home. This is a richer representation built from the enum; C# does not let a class inherit from an enum.
Between components using the same shared object definition, the enum already provides a common vocabulary. The database problem arises when persisted values outlive that definition. The Enumeration class keeps the application representation useful while making its storage mapping deliberate.
I have started adding Specification to the enum type's name to distinguish the two roles. PaymentStatusSpecification declares the enum values. PaymentStatus is the richer Enumeration class generated from them. The suffix is a naming convention, not a C# language feature.
Declare the values once
With the IFX Enumeration generator available in the consuming project, the declaration is small:
using Ifx.Generators.Attributes;
namespace Example;
[GenerateEnumeration(
"PaymentStatus",
nameof(PaymentStatusSpecification.UNKNOWN))]
public enum PaymentStatusSpecification
{
UNKNOWN = 0,
PENDING = 10,
AUTHORIZED = 15,
SETTLED = 20,
FAILED = 30
}
The generator creates PaymentStatus as a sealed class derived from Ifx.Primitives.Enumeration. It supplies named instances, an All collection, equality, and the FromName and FromValue lookup methods. There is no conversion switch for me to write or keep synchronized with the enum.
The generated class inherits Id and Name from the base class. In this example, the uppercase member names are deliberately the persistent string codes from the database article. The numbers remain available for enum use within the application; the database stores the names.
The declaration is the input. The conversion implementation is generated at build time.
Use the generated conversion
Reading and writing a string value now uses the generated API:
var status = PaymentStatus.FromName("SETTLED");
var storedStatusCode = status.Name; // "SETTLED"
var fromSharedEnum = PaymentStatus.FromValue(
(int)PaymentStatusSpecification.SETTLED);
bool sameStatus = status == fromSharedEnum; // true
This removes the hand-written mapping methods. It does not remove the need to decide which strings are valid and how to handle a failed conversion.
The current generator uses exact, case-sensitive name matching and returns the configured fallback for null, blank, or unrecognized names. Here that fallback is UNKNOWN. A database boundary can reject it while retaining the original input for investigation:
var status = PaymentStatus.FromName(storedStatusCode);
if (status == PaymentStatus.UNKNOWN)
{
throw new InvalidOperationException(
$"Unrecognized payment status: {storedStatusCode}");
}
In this example, UNKNOWN is a conversion sentinel, not an allowed payment state in the database. An import could quarantine the row instead of throwing. The important decision is to avoid quietly treating failed conversion as Pending or Settled.
Keep the stored meaning stable
This version of the generator takes Name directly from the enum member name. It does not support a separate storage-code attribute. Once SETTLED is stored, renaming that member becomes a compatibility change and needs a deliberate migration or mapping policy.
Display text belongs elsewhere. The interface can show “Payment received” without changing the stored SETTLED code. Localized labels should not redefine historical data.
The database contract remains separate. Constraints, reference data, and application mappings still need to agree. Generated conversion makes the application side consistent; it does not enforce that agreement across deployments by itself.
Let the extra structure earn its place
An ordinary enum with an explicit mapping to storage codes and boundary validation may be sufficient. An extension method may be enough for one shared rule. A list that administrators can extend without changing application behavior may belong in a reference table and an ordinary entity.
I prefer Enumeration when several callers need the same identity or conversion rules. The generator keeps the repetitive implementation out of the hand-written code while leaving the specification visible.
That leaves a smaller set of decisions to review: the names, identifiers, fallback, and persistence policy. The next article examines those generator decisions and where the defaults deserve closer attention.