How can i make dapper use the string value of an enum. In the example below it uses the numerical value of the enum. On read from the database, dapper correctly converts string to enum.
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 column Cat I have value 1
instead of A
The easiest way I think is:
connection.Execute("Insert into Products (Cat, Id) Values ", new { p.Id, Cat = p.Cat.ToString());