1
votes

I have built an EdmModel which contains an enum property, Level.

var level = new EdmEnumType("Log.Api.Models",
                            "Level",
                            EdmPrimitiveTypeKind.Int32,
                            false);
level.AddMember(new EdmEnumMember(level, "Debug", new EdmIntegerConstant(0)));
level.AddMember(new EdmEnumMember(level, "Error", new EdmIntegerConstant(1)));
level.AddMember(new EdmEnumMember(level, "Info", new EdmIntegerConstant(2)));
Model.AddElement(level);

// add a property, named 'Level', of type 'Level'
logEntry.AddProperty(new EdmStructuralProperty(logEntry,
                                               "Level",
                                               new EdmEnumTypeReference(level, false)));

OData requests are then parsed in C# using

ODataUriParser.ParseFilter(filter,
                           Model,
                           (IEdmSchemaType) schemaElmnt);

But I'm so far unsuccessful in sending a request which specifies an enum value. I've tried with the fully-qualified enum...

"Level eq Log.Api.Models.Level.Error"

And without

"Level eq Error"

And I've tried enclosing it in single quotes

"Level eq 'Error'"

The exception message is

A binary operator with incompatible types was detected. Found operand types 'Log.Api.Models.Level' and 'Edm.String' for operator kind 'Equal'.'

What is the correct format? Or does the problem lie in my EdmModel?

1

1 Answers

0
votes

The correct format is odd and is unintuitive, but it looks like this:

Fully.Qualified.Enum.Type'EnumValue'

Used in your example:

Level eq Log.Api.Models.Level'Error'

The official V4 documentation describes the format of literals in the $filter system query option:

http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/part2-url-conventions/odata-v4.0-errata03-os-part2-url-conventions-complete.html#_Toc371341809