Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to manually build a WCF Data Service using a POCO data model and I cannot figure out how to properly expose enum values. Assuming a simple model like:

public class Order
{
   public int ID {get; set;}
   public string Description {get; set;}
   public OrderStatus Status {get; set;}
}

public enum OrderStatus
{
   New,
   InProcess,
   Complete
}

How do you expose the valuable information in the OrderStatus property via the OData WCF Data Service?

If you do nothing, the Data Service generates a runtime error (enum is invalid property). The only answer I've seen that at least resolves the error is to mark the enum property as Ignored, such as:

[System.Data.Services.IgnoreProperties("Status")]
public class Order ...

This works, but it forces you to "omit" valuable information from the service layer. Are there other options for working with enum values in WCF Data Services?

EDIT: Please notice this is WCF Data Services (aka Astoria). This is not raw WCF Services, in which case the answers are more clear.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
196 views
Welcome To Ask or Share your Answers For Others

1 Answer

Enums are currently not supported in WCF Data Services (the OData protocol doesn't support them either). The typical workaround is to use string and constant values, or integer and constant values.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...