How to force dapper to use the string value of an enumeration. The example below uses the numerical value of an enumeration. When reading from a database, dapper correctly converts a string into an enumeration.
public enum Category { A, B }
public Product
{
public Category Cat {get;set;}
public int Id {get;set;}
}
Product p = new Product() {Cat = Category.A, Id=22} ;
connection.Execute("Insert into Products (Cat, Id) Values ",p);
In this case, in the database in the Cat column, I have a value 1insteadA
source
share