[英]How do I serialize an enum as part of a DataContract from Code First Entity Framework
I'm writing a WCF service that uses Code First Entity Framework to access a SQL Server database. 我正在编写一个WCF服务,该服务使用“代码优先实体框架”访问SQL Server数据库。 I have a POCO that references an enum
JobStatus
: 我有一个POCO引用枚举
JobStatus
:
public enum JobStatus
{
New,
Submitted,
Approved,
Returned,
OnHold,
Cancelled,
}
Now I'm defining a DTO based on my POCO as part of a WCF [DataContract]
. 现在,我将基于POCO的DTO定义为WCF
[DataContract]
。 How should I reference the enum in my DTO? 我应该如何在DTO中引用枚举? I'm going to need that enum in my MVC application as well to interpret the data being retrieved.
我将在我的MVC应用程序中也需要该枚举,以解释要检索的数据。 Is this a situation where I need to create an assembly that only contains the enums and ship that around or is there a better way to deal with this?
是在这种情况下,我需要创建一个仅包含枚举的程序集并将其运送到周围,还是有更好的方法来解决此问题?
why do you think that it would be such a problem trying to treat enum just like any other data member http://msdn.microsoft.com/en-us/library/aa347875.aspx 您为什么认为像对待其他任何数据成员一样对待枚举将是一个问题,例如http://msdn.microsoft.com/en-us/library/aa347875.aspx
DataContract(Name = "JobStatus")]
public enum JobStatus
{
[EnumMember]
New,
[EnumMember]
Submitted,
[EnumMember]
Approved,
[EnumMember]
Returned,
[EnumMember]
OnHold,
[EnumMember]
Cancelled,
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.