3
我有一個類,和類似的屬性。我在Mysql中使用實體框架。 遷移後使用add-migration
,它將創建一個INT(11)
列。 但我需要VARCHAR
因爲我需要Dept或Credit值。枚舉到實體框架的字符串
我嘗試了很多,但沒有。
我該怎麼辦?
public class trns
{
public trans_type enm_trans_type { get; set; }
}
public enum trans_type {
[Description("Dept")]
Dept,
[Description("Credit")]
Credit
}
它將通過使用CodeFirst,您將需要下面的反向版本http://stackoverflow.com/questions/7437952/map-string-column-in-entity-framework-to-enum一篇好文章將是http://nodogmablog.bryanhogan.net/2014/11/saving-enums-as-strings-with-entity-framework/ –
是的,這是正確的。 http://nodogmablog.bryanhogan.net/2014/11/saving-enums-as-strings-with-entity-framework/ – caras