Skip to content

Commit 6f03bce

Browse files
author
Sergei Koshel
committed
Added value types support to the filters isnull & isnotnull.
1 parent cc46a60 commit 6f03bce

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,27 @@ private static Expression GetFilterExpressionLambda(Expression left, Expression
170170
break;
171171
case FilterOperations.isnotnull:
172172
// {model.Id != null}
173-
body = Expression.NotEqual(left, right);
173+
if (left.Type.IsValueType)
174+
{
175+
var nullableType = typeof(Nullable<>).MakeGenericType(left.Type);
176+
body = Expression.NotEqual(Expression.Convert(left, nullableType), right);
177+
}
178+
else
179+
{
180+
body = Expression.NotEqual(left, right);
181+
}
174182
break;
175183
case FilterOperations.isnull:
176184
// {model.Id == null}
177-
body = Expression.Equal(left, right);
185+
if (left.Type.IsValueType)
186+
{
187+
var nullableType = typeof(Nullable<>).MakeGenericType(left.Type);
188+
body = Expression.Equal(Expression.Convert(left, nullableType), right);
189+
}
190+
else
191+
{
192+
body = Expression.Equal(left, right);
193+
}
178194
break;
179195
default:
180196
throw new JsonApiException(500, $"Unknown filter operation {operation}");

0 commit comments

Comments
 (0)