在实体框架来枚举映射字符串列 [英] Map string column in Entity Framework to Enum

查看:149
本文介绍了在实体框架来枚举映射字符串列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来映射一个字符串列在实体模型枚举?

Is there a way to map a string column to an enum in an Entity Model?

我在Hibernate中做到了这一点,但不能算出它在。EMF

I have done this in Hibernate, but can't figure it out in EMF.

推荐答案

这是丑陋的,但对于映射枚举为字符串,我发现这样的:

It is ugly, but for mapping enums to strings I found something like this:

public virtual string StatusString
{
    get { return Status.ToString(); }
    set { OrderStatus newValue; 
          if (Enum.TryParse(value, out newValue))
          { Status = newValue; }
        }
}

public virtual OrderStatus Status { get; set; } 



OrderStatus是枚举类型,状态是普查员和StatusString是它的字符串版本。

OrderStatus is the enumerator type, Status is the enumerator and StatusString is the string version of it.

这篇关于在实体框架来枚举映射字符串列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆