Azure表存储,WCF服务和枚举 [英] Azure Table Storage, WCF Service and Enum
问题描述
PaymentStatus
的属性,这是一个定义如下的枚举
: public enum PaymentStatuses:int
{
OnDelivery = 1,
付费= 2,
已处理= 3,
清除= 4
}
该类本身,属性定义非常简单:
public PaymentStatuses? PaymentStatus {get;组; }
但是,如果我尝试将订单保存到Azure Table Storage,我会收到以下异常:
System.InvalidOperationException:Order + PaymentStatuses类型没有可设置的属性。
此时我以为使用枚举
isn不可能,但是一个快速的Google搜索返回: http://social.msdn.microsoft.com/Forums/en-US/windowsazure/thread/7eb1a2ca-6c1b-4440-b40e-012db98ccb0a
此页面列出了两个答案,其中一个似乎忽略了这些问题,并建议在Azure Storage中使用枚举
。
现在,我不需要在Azure Table Storage中存储枚举
,所以我也可以存储相应的 int
,但是,我确实需要这个属性在WCF服务中公开。
我试过属性使用获取
和设置
从a $中返回枚举
存储 integer
,并使用 WritingEntity从Azure中删除此属性
事件在我的 DataContext
,但是在该实体的事件触发之前我收到该异常。
在这一点上,我很失落,我不知道在WCF中有这个属性可以做什么,作为一个枚举
,但是Azure存储只是 int
。
不支持枚举。即使它被定义为一个int,它实际上不是表存储支持的一个整体类型。 以下是支持的类型列表。枚举只是一个字符串表达式一个具有面向对象风格的整数。
您可以在表存储中存储int,然后使用Enum.Parse隐藏它。
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; }
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.
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
This page lists two answers, one of which seems to ignore the problems and suggests that using an enum
in Azure Storage is fine.
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.
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.
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
.
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.
You can store int in table storage and then covert it using Enum.Parse.
这篇关于Azure表存储,WCF服务和枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!