pdevito3 / QueryKit

šŸŽ›ļø QueryKit is a .NET library that makes it easier to query your data by providing a fluent and intuitive syntax for filtering and sorting.
Apache License 2.0
152 stars 13 forks source link

Filtering Guid nullable throws System.ArgumentException #36

Closed Modkmi closed 6 months ago

Modkmi commented 6 months ago

When filtering Guid nullable field, it throws System.ArgumentException: Method 'System.String ToString()' declared on type 'System.Guid' cannot be called with instance of type 'System.Nullable1[System.Guid]'`. Environment info: .NET 8 web api with EF Core

Used query: filter="accountId==\"639940b9-8fee-4df6-6fad-08dc429a430c\"", where property is: public Guid? AccountId { get; set; }

Stack trace: System.ArgumentException: Method 'System.String ToString()' declared on type 'System.Guid' cannot be called with instance of type 'System.Nullable`1[System.Guid]' at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method) at QueryKit.FilterParser.<>c__DisplayClass26_0`1.<ComparisonExprParser>b__4(<>f__AnonymousType10`3 temp) at Sprache.Parse.<>c__DisplayClass32_0`2.<Select>b__0(T t) at Sprache.Parse.<>c__DisplayClass26_0`2.<Then>b__1(IResult`1 s) at Sprache.Parse.<>c__DisplayClass36_0`1.<Or>b__0(IInput i) at Sprache.Parse.<>c__DisplayClass26_0`2.<Then>b__0(IInput i) at Sprache.Parse.<>c__DisplayClass26_0`2.<Then>b__0(IInput i) at Sprache.Parse.<>c__DisplayClass31_0`1.<End>b__0(IInput i) at Sprache.ParserExtensions.TryParse[T](Parser`1 parser, String input) at Sprache.ParserExtensions.Parse[T](Parser`1 parser, String input) at QueryKit.FilterParser.ParseFilter[T](String input, IQueryKitConfiguration config) at QueryKit.QueryableExtensions.ApplyQueryKitFilter[TEntity](IQueryable`1 source, String filter, IQueryKitConfiguration config)

Modkmi commented 6 months ago

Just a note, it's not related to v1.3.2, since it was happening in v.1.3.0, just a different error: QueryKit.Exceptions.ParsingException: There was a parsing failure, likely due to an invalid comparison or logical operator. You may also be missing double quotes surrounding a string or guid. ---> System.InvalidOperationException: The binary operator Equal is not defined for the types 'System.Nullable1[System.Guid]' and 'System.Guid'. 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 QueryKit.Operators.ComparisonOperator.EqualsType.GetExpression[T](Expression left, Expression right, Type dbContextType) at QueryKit.FilterParser.<>c__DisplayClass26_01.b4(<>fAnonymousType103 temp) at Sprache.Parse.<>c__DisplayClass32_02.