This is my Model Class where we have a Type which could be a Zombie or Human
public class User
{
public int ID { get; set; }
public string Name { ge
You can save the enum to the db as a string, and I agree with dotctor that it is not the best idea, but if you need to, you need to make a few changes.
public class User
{
public int ID { get; set; }
public string Name { get; set; }
public List WeposInList { get; set; }
[Column("Type")]
public string TypeString
{
get { return Type.ToString(); }
private set { Type= value.ParseEnum(); }
}
[NotMapped]
public Type Type { get; set; }
}
Add this extension class to your project.
public static class StringExtensions
{
public static T ParseEnum(this string value)
{
return (T)Enum.Parse(typeof(T), value, true);
}
}
Full details are here - http://NoDogmaBlog.bryanhogan.net/2014/11/saving-enums-as-strings-with-entity-framework/