Describe the bug
I am trying Hotchocolate with EF Core.
When i filter by enum using IN or NOT_IN, i got and exception below.
Something about interface covariance and value types i guess it is invalid expression.
EF works:
var enums = new[] {TestEnum.One, TestEnum.Two};
var entities = databaseContext.Entities.Where(x => enums.Contains(x.TestEnum)).ToArray();
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Filtering with IN/NOT_IN (I tested only them) is working
Desktop (please complete the following information):
Additional context
SampleQuery:
{
entities(where: {testEnum_in: [ONE, TWO]}) {
testEnum
}
}
StackTrace:
Unable to cast object of type 'System.Collections.Generic.List`1[Sample.TestEnum]' to type 'System.Collections.Generic.IEnumerable`1[System.Object]'.
at Microsoft.EntityFrameworkCore.Query.QuerySqlGenerator.VisitIn(InExpression inExpression)
at Microsoft.EntityFrameworkCore.Query.SqlExpressionVisitor.VisitExtension(Expression extensionExpression)
at System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.QuerySqlGenerator.VisitSelect(SelectExpression selectExpression)
at Microsoft.EntityFrameworkCore.Query.QuerySqlGenerator.GetCommand(SelectExpression selectExpression)
at Microsoft.EntityFrameworkCore.Query.Internal.RelationalCommandCache.GetRelationalCommand(IReadOnlyDictionary`2 parameters)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.InitializeReader(DbContext _, Boolean result)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementation[TState,TResult](Func`3 operation, Func`3 verifySucceeded, TState state)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
at System.Linq.Queryable.Count[TSource](IQueryable`1 source)
at HotChocolate.Types.Relay.QueryableConnectionResolver`1.Create()
at HotChocolate.Types.Relay.QueryableConnectionResolver`1.<HotChocolate.Types.Relay.IConnectionResolver.ResolveAsync>b__8_0()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.<>c.<.cctor>b__274_0(Object obj)
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
at HotChocolate.Types.Relay.QueryableConnectionMiddleware`1.InvokeAsync(IMiddlewareContext context)
at HotChocolate.Execution.ExecutionStrategyBase.ExecuteMiddlewareAsync(ResolverContext resolverContext, IErrorHandler errorHandler)
Potential issue of comparable, investigating.
I'm currently writing integration tests fro all filters to avoid these issue in the future
@sergeyshaykhullin I cannot really replicate this behaviour. What provider are you using? can you provide an min. repo?
You can check the test case below:
@sergeyshaykhullin and me were debugging a little. Turns out the EF Provider of PostgreSQL does not like Lists.
https://github.com/npgsql/efcore.pg/issues/1278
We can povide a fix for this with along #1688
Most helpful comment
Potential issue of comparable, investigating.
I'm currently writing integration tests fro all filters to avoid these issue in the future