Related: OData/odata.net#3415
Currently if I have a nullable property (like int?) used in an alternate key ODataPathQueryBuilder throws an exception when processing the generated KeySegment (with an int constant value):
System.InvalidOperationException: The binary operator Equal is not defined for the types 'System.Nullable`1[System.Int32]' and 'System.Int32'.
at System.Linq.Expressions.Expression.GetEqualityComparisonOperator(ExpressionType binaryType, String opName, Expression left, Expression right, Boolean liftToNull)
at System.Linq.Expressions.Expression.Equal(Expression left, Expression right, Boolean liftToNull, MethodInfo method)
at ...\ODataPathQueryBuilder.cs:line 69
...
Replacing:
|
IEnumerable<BinaryExpression> conditions = keySegment.Keys.Select(kvp => |
|
Expression.Equal( |
|
Expression.Property(filterParam, kvp.Key), |
|
Expression.Constant(kvp.Value))); |
With:
IEnumerable<BinaryExpression> conditions = keySegment.Keys.Select(kvp => {
Expression prop = Expression.Property(filterParam, kvp.Key);
Expression cons = Expression.Constant(kvp.Value);
if (prop.Type != cons.Type)
cons = Expression.Convert(cons, prop.Type);
return Expression.Equal(prop, cons);
});
Seems to solve the issue
Related: OData/odata.net#3415
Currently if I have a nullable property (like int?) used in an alternate key ODataPathQueryBuilder throws an exception when processing the generated KeySegment (with an int constant value):
Replacing:
WebApi/src/Microsoft.AspNet.OData.Shared/Query/ODataPathQueryBuilder.cs
Lines 68 to 71 in 1b8f45e
With:
Seems to solve the issue