![]() So while an enum does provide us a convenient mechanism for constraining our type’s values, it leaves us constantly having to convert (and validate) to and from the string representation. Our persistence layer uses Dapper and like most other ORMs it persists Enums using the backing integer value. Unfortunately, this throws a bit of a wrench into our plans to use an enum. ![]() When persisted to the database or JSON-serialized, the value must be a string. Not so fast… You haven’t heard the rest of the requirements. That’s it? That’s not interesting! Just use an enum. Strings are far more readable in database query results and when parsing JSON output from an API.Ī client recently presented us with this challenge.Īdd a property to an existing class which is constrained to a limited set of values. ![]() Most tools will serialize or save your enums using that integer value.īut what if you need to save it as a string?
0 Comments
Leave a Reply. |