public enum BloodType { APos, ANeg, BPos, BNeg, AbPos, AbNeg, OPos, ONeg }

public static class BloodTypeExtensions
{
    public static string ToDbString(this BloodType t) => t switch
    {
        BloodType.APos  => "A+",
        BloodType.ANeg  => "A-",
        BloodType.BPos  => "B+",
        BloodType.BNeg  => "B-",
        BloodType.AbPos => "AB+",
        BloodType.AbNeg => "AB-",
        BloodType.OPos  => "O+",
        BloodType.ONeg  => "O-",
        _ => throw new ArgumentOutOfRangeException(nameof(t))
    };

    public static BloodType FromDbString(string v) => v switch
    {
        "A+"  => BloodType.APos,
        "A-"  => BloodType.ANeg,
        "B+"  => BloodType.BPos,
        "B-"  => BloodType.BNeg,
        "AB+" => BloodType.AbPos,
        "AB-" => BloodType.AbNeg,
        "O+"  => BloodType.OPos,
        "O-"  => BloodType.ONeg,
        _ => throw new ArgumentOutOfRangeException(nameof(v), $"Unknown blood type: '{v}'")
    };

    public static bool TryFromDbString(string? v, out BloodType result)
    {
        if (v is null) { result = default; return false; }
        try { result = FromDbString(v); return true; }
        catch (ArgumentOutOfRangeException) { result = default; return false; }
    }
}