Azure的表的存储,WCF服务和枚举 [英] Azure Table Storage, WCF Service and Enum
问题描述
下面是我的问题。它定义了一个订单一类有一个叫做 PaymentStatus
属性,它是一个枚举
像这样定义的:
Here's my problem. A class which defines an order has a property called PaymentStatus
, which is an enum
defined like so:
public enum PaymentStatuses : int
{
OnDelivery = 1,
Paid = 2,
Processed = 3,
Cleared = 4
}
,后来,在类中,属性定义很简单:
And later on, in the class itself, the property definition is very simple:
public PaymentStatuses? PaymentStatus { get; set; }
不过,如果我尝试保存,以在Azure表存储时,我得到以下异常:
However, if I try to save an order to the Azure Table Storage, I get the following exception:
System.InvalidOperationException: The type Order+PaymentStatuses' has no settable properties.
在这一点上我想用枚举
是不可能的,但快速谷歌搜索返回此:<一href=\"http://social.msdn.microsoft.com/Forums/en-US/windowsazure/thread/7eb1a2ca-6c1b-4440-b40e-012db98ccb0a\">http://social.msdn.microsoft.com/Forums/en-US/windowsazure/thread/7eb1a2ca-6c1b-4440-b40e-012db98ccb0a
At this point I thought using enum
isn't possible, but a quick Google search returned this: http://social.msdn.microsoft.com/Forums/en-US/windowsazure/thread/7eb1a2ca-6c1b-4440-b40e-012db98ccb0a
本页面列出了两个答案,其中一个似乎忽略的问题,并建议在Azure存储使用枚举
的罚款。
This page lists two answers, one of which seems to ignore the problems and suggests that using an enum
in Azure Storage is fine.
现在,我并不需要存储的枚举
中的Azure表的存储正因为如此,我也可以同样存储对应的 INT
,但是,我确实需要这个属性在WCF服务暴露出来。
Now, I don't NEED to store the enum
in the Azure Table Storage as such, I could just as well store a corresponding int
, however, I do need this property to be exposed in the WCF service.
我试图使物业使用 GET
和设置
返回枚举
从存储整数
,并通过使用 WritingEntity
活动中删除从Azure的这个属性我的的DataContext
,但我得到的例外该实体的事件被触发之前。
I've tried making the property use get
and set
to return the enum
from a stored integer
, and remove this property from Azure by using the WritingEntity
event on my DataContext
, but I get that exception before the event for this entity is fired.
在这一点上,我不知所措,我不知道我能做些什么,以在WCF中这个属性为枚举
,但有天青店刚 INT
。
At this point, I'm at a loss, I don't know what else I can do to have this property in WCF as an enum
, but have Azure store just the int
.
推荐答案
不支持枚举。即使是像一个int定义,实在是不表的存储支持的整型。 下面是支持的类型列表中。的枚举只是一个字符串前的pression整数与面向对象的味道
Enum is not supported. Even though it is defined like an int, it is really not a integral type supported by Table Storage. Here is the list of types supported. An enum is just a string expression of an integral number with an object-oriented flavor.
您可以在表存储INT存储,然后使用Enum.Parse隐蔽了。
You can store int in table storage and then covert it using Enum.Parse.
这篇关于Azure的表的存储,WCF服务和枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!