odata error - operator with incompatible types was detected

8k views Asked by At

I'm new to odata and WebApi. I'm trying to send the following odata query: ?$filter=ExternalIds eq '5'

ExternalIds is part of an object and define as:


public Id ExternalIds { get; set; }

public class Id { [DataMember] public string Name { get; set; } [DataMember] public string Value { get; set; } }

i'm getting the error: "A binary operator with incompatible types was detected. Found operand types 'GenericAPIInterface.Entities.User.Id' and 'Edm.String' for operator kind 'Equal'."

2

There are 2 answers

0
Mark Stafford - MSFT On BEST ANSWER

In order to use the property values on a related class you will need to use the navigation syntax within $filter, e.g. ...?$filter=ExternalIds/Value eq '5'. Also, if ExternalIds is an entity (has it's own id), you may want to expand it using $expand. This is not strictly necessary for the filter clause to work, however.

0
Pawel Gorczynski On

I think I just had the same problem - turned out that I used a query Id eq "5" while it should have been Id eq 5 so unquoting basically helped.