3

I have an enum that looks like this:

enum Color : byte
{
    Transparent,
    White,
    Black
}

When I request the values from my Entity I get the results as strings, not integers, example:

{
    "Color": "White"
}

Is there any way to make OData return the value instead of the name of the value?

I'm using Microsoft.AspNet.OData v6.1.0, Microsoft.OData.Core v7.2.0, and Microsoft.Odata.Edm v7.2.0.

The target framework is .Net Framework 4.6.1.

Emerson Jair
  • 128
  • 7

1 Answers1

0

You can try to add a new property, like this:

public byte ColorInt { get { return (byte)Color; }}

I had that same issue and the only solution I found after searching a lot was that.

If you don't want the Color property to be returned you can decorate it with JsonIgnore atribute.

Rodrigo Werlang
  • 2,118
  • 1
  • 17
  • 28