David Clarke
David Clarke

Reputation: 13266

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. I have a POCO that references an enum 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]. How should I reference the enum in my DTO? I'm going to need that enum in my MVC application as well to interpret the data being retrieved. 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?

Upvotes: 0

Views: 256

Answers (1)

COLD TOLD
COLD TOLD

Reputation: 13599

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

DataContract(Name = "JobStatus")]
public enum JobStatus
{
    [EnumMember]
    New, 
    [EnumMember]
    Submitted,
    [EnumMember]
    Approved,
    [EnumMember]
    Returned,
    [EnumMember]
    OnHold,
    [EnumMember]
    Cancelled,
}

Upvotes: 1

Related Questions