Skip to content

Commit a3d9e6c

Browse files
committed
fixed it
1 parent c457f6e commit a3d9e6c

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,14 @@ public static IQueryable<TSource> Filter<TSource>(this IQueryable<TSource> sourc
127127
return source.Where(lambdaIn);
128128
}
129129
else
130-
{ // convert the incoming value to the target value type
130+
{
131+
var isNullabe = IsNullable(property.PropertyType);
132+
var propertyValue = filterQuery.PropertyValue;
133+
var value = isNullabe && propertyValue == "" ? null : propertyValue;
134+
135+
// convert the incoming value to the target value type
131136
// "1" -> 1
132-
var convertedValue = TypeHelper.ConvertType(filterQuery.PropertyValue, property.PropertyType);
137+
var convertedValue = TypeHelper.ConvertType(value, property.PropertyType);
133138
// {model}
134139
var parameter = Expression.Parameter(concreteType, "model");
135140
// {model.Id}
@@ -204,6 +209,9 @@ public static IQueryable<TSource> Filter<TSource>(this IQueryable<TSource> sourc
204209
}
205210
}
206211

212+
private static bool IsNullable(Type type) => type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>);
213+
214+
207215
private static Expression GetFilterExpressionLambda(Expression left, Expression right, FilterOperations operation)
208216
{
209217
Expression body;

test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public async Task Can_Filter_TodoItems_Using_NotEqual_Operator()
100100
_context.SaveChanges();
101101

102102
var httpMethod = new HttpMethod("GET");
103-
var route = $"/api/v1/todo-items?filter[updated-date]=ne:null";
103+
var route = $"/api/v1/todo-items?filter[updated-date]=ne:";
104104
var request = new HttpRequestMessage(httpMethod, route);
105105

106106
// Act

0 commit comments

Comments
 (0)