2

I have a simple class, of which one of the properties is an enum. For example:

public class Person
{
    public string Name { get; set; }
    public int Age { get; set; }
    public Gender Gender { get; set; }
}

public enum Gender 
{
    [EnumMember(Value = "M")]
    Male, // database uses 'M' instead of 'Male'

    [EnumMember(Value = "F")]
    Female // database uses 'F' instead of 'Female'
}

My data is stored with slightly different values for Gender - M instead of Male, and F instead of Female. For example:

enter image description here

How can I map the DB value of M to the enum value of Gender.Male, and likewise, F to Gender.Female?

1
  • Dapper sees enums as their base types. Commented Jul 3, 2019 at 16:09

1 Answer 1

2

There is an opened issue in Dapper for this use case: #259. Looks like aliases for enums are not possible until it's fixed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.