应对滞后的枚举支持
在 EF 5.0(计划很快发布)之前,实体框架将不支持枚举。
http://blogs.msdn.com/b/efdesign/archive/2011/06/29/enumeration-support-in-entity-framework.aspx
WCF 数据服务(以及 oData 标准) 不支持枚举
我们知道枚举很常见,不幸的是他们从未遇到过 到目前为止。它们在我们下一步要做的事情清单上排名相当靠前 虽然
(请参阅:https://stackoverflow.com/a/3571378/141172)
我已经开始了一个新项目,并且将枚举替换为以下内容:
public static class MyEnum
{
public const int MyValue = 0;
public const int AnotherValue = 1;
}
我牺牲了枚举提供的保证,即仅分配定义的值,以便利用重要的(此时相当成熟的)基础设施服务。
有没有更好的方法来处理滞后的枚举支持?一旦 EF 和 WCF 数据服务添加了枚举支持,是否可能会出现另一个重要的框架,它会像这两个框架一样缓慢地引入枚举支持?
The Entity Framework will not support enum's until EF 5.0 (scheduled to ship soon).
Entity Framework 4.2 enum support
http://blogs.msdn.com/b/efdesign/archive/2011/06/29/enumeration-support-in-entity-framework.aspx
WCF Data Services (and the oData standard) to not support enums
We understand that enums are common, unfortunately they never met tha
bar so far. They are rather high on our list of things to do next
though
(See: https://stackoverflow.com/a/3571378/141172)
I have begun a new project and am replacing enum's with something like:
public static class MyEnum
{
public const int MyValue = 0;
public const int AnotherValue = 1;
}
I'm sacrificing the guarantee that enum's provide that only defined values will be assigned in order to utilize important (and at this point fairly mature) infrastructure services.
Is there a better way to handle lagging enum support? Once EF and WCF Data Services add enum support, is there likely to be another important framework on the horizon that will introduce enum support as slowly as these two have?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用带有私有构造函数的结构来为每个值定义一个公共静态成员吗:
注意:我实际上还没有尝试过这一点。
Could you use a struct with a private constructor that defines a public static member for each value:
Note: I haven't actually tried this out.
比您的示例更好的是使用枚举来保存常量值并每次都转换为 int 。这样你至少可以在任何可能的地方使用枚举而不是失去一切。
枚举永远不会提供不可避免的类型安全。但是,通过将枚举的使用尽可能扩展到应用程序代码和业务逻辑中,您可以获得越来越多的安全性,以防止微妙的使用错误。
Well better than your example would be using an enum to hold the constant values and casting to int everytime. That way you can at least use the enum whereever it is possible rather than loosing everything.
enums never provide inescapable type-safety. But by extending the usage of enums as far as you can into the applications code and business logic, you get more and more safety against subtle usage errors.