Using enums in WCF Data Services

前端 未结 6 2021
独厮守ぢ
独厮守ぢ 2020-12-14 09:43

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 lik

6条回答
  •  鱼传尺愫
    2020-12-14 10:26

    Maybe we can "cheat" it with the below workaround:

    [System.Data.Services.IgnoreProperties("Status")]
    public class Order
    {
       public int ID {get; set;}
       public string Description {get; set;}
       public OrderStatus Status {get; set;}
       public int StatusValue
       {
          get
          {
               return (int)this.Status;
          }
          set
          {
              // Add validation here
              this.Status = (OrderStatus)value;
          } 
       }
    }
    
    public enum OrderStatus
    {
       New,
       InProcess,
       Complete
    }
    

提交回复
热议问题