Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query: conditional operator with type check throws InvalidOperationException #16335

Closed
roji opened this issue Jun 28, 2019 · 2 comments · Fixed by #16351
Closed

Query: conditional operator with type check throws InvalidOperationException #16335

roji opened this issue Jun 28, 2019 · 2 comments · Fixed by #16351
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@roji
Copy link
Member

roji commented Jun 28, 2019

The following throws InvalidOperationException:

var rssBlog = context.Set<Blog>()
    .Where(x => x is Blog ? false : true)
    .ToList();

Exception:

System.InvalidOperationException : Operation is not valid due to the current state of the object.
   at Microsoft.EntityFrameworkCore.Relational.Query.Pipeline.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateWhere(ShapedQueryExpression source, LambdaExpression predicate) in /home/roji/projects/EFCore/src/EFCore.Relational/Query/Pipeline/RelationalQueryableMethodTranslatingExpressionVisitor.cs:line 814
   at Microsoft.EntityFrameworkCore.Query.Pipeline.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression) in /home/roji/projects/EFCore/src/EFCore/Query/Pipeline/QueryableMethodTranslatingExpressionVisitor.cs:line 425
   at Microsoft.EntityFrameworkCore.Relational.Query.Pipeline.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression) in /home/roji/projects/EFCore/src/EFCore.Relational/Query/Pipeline/RelationalQueryableMethodTranslatingExpressionVisitor.cs:line 61
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.Pipeline.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query) in /home/roji/projects/EFCore/src/EFCore/Query/Pipeline/QueryCompilationContext.cs:line 58
   at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async) in /home/roji/projects/EFCore/src/EFCore/Storage/Database.cs:line 72
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async) in /home/roji/projects/EFCore/src/EFCore/Query/Internal/QueryCompiler.cs:line 108

Confirmed on 4f1f019

@smitpatel
Copy link
Contributor

Assigning to @roji
x is Blog is EntityReferenceExpression in the tree at translation pipeline. It should have been removed earlier.

@smitpatel smitpatel assigned roji and unassigned smitpatel Jun 28, 2019
@smitpatel
Copy link
Contributor

[ConditionalTheory]
        [MemberData(nameof(IsAsyncData))]
        public virtual Task Where_is_conditional(bool isAsync)
        {
            var customer = new Customer();

            return AssertQuery<Product>(
                isAsync,
                ps => ps.Where(p => p is Product ? false : true));
        }

@smitpatel smitpatel added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jul 1, 2019
@ajcvickers ajcvickers modified the milestones: 3.0.0, 3.0.0-preview7 Jul 2, 2019
@ajcvickers ajcvickers modified the milestones: 3.0.0-preview7, 3.0.0 Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants