Skip to content

Commit

Permalink
Query: Throw better exception message when composing after client pro…
Browse files Browse the repository at this point in the history
…jection
  • Loading branch information
smitpatel committed Aug 29, 2019
1 parent 5b0fdfb commit 1d9edf1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,10 @@ protected override Expression VisitExtension(Expression extensionExpression)
return Visit(entityShaperExpression.ValueBufferExpression);

case ProjectionBindingExpression projectionBindingExpression:
var selectExpression = (SelectExpression)projectionBindingExpression.QueryExpression;
return selectExpression.GetMappedProjection(projectionBindingExpression.ProjectionMember);
return projectionBindingExpression.ProjectionMember != null
? ((SelectExpression)projectionBindingExpression.QueryExpression)
.GetMappedProjection(projectionBindingExpression.ProjectionMember)
: null;

case NullConditionalExpression nullConditionalExpression:
return Visit(nullConditionalExpression.AccessOperation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,10 @@ protected override Expression VisitExtension(Expression extensionExpression)
return Visit(entityShaperExpression.ValueBufferExpression);

case ProjectionBindingExpression projectionBindingExpression:
return ((InMemoryQueryExpression)projectionBindingExpression.QueryExpression)
.GetMappedProjection(projectionBindingExpression.ProjectionMember);
return projectionBindingExpression.ProjectionMember != null
? ((InMemoryQueryExpression)projectionBindingExpression.QueryExpression)
.GetMappedProjection(projectionBindingExpression.ProjectionMember)
: null;

case NullConditionalExpression nullConditionalExpression:
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,10 @@ protected override Expression VisitExtension(Expression extensionExpression)
return Visit(entityShaperExpression.ValueBufferExpression);

case ProjectionBindingExpression projectionBindingExpression:
var selectExpression = (SelectExpression)projectionBindingExpression.QueryExpression;
return selectExpression.GetMappedProjection(projectionBindingExpression.ProjectionMember);
return projectionBindingExpression.ProjectionMember != null
? ((SelectExpression)projectionBindingExpression.QueryExpression)
.GetMappedProjection(projectionBindingExpression.ProjectionMember)
: null;

default:
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Xunit;
using Xunit.Abstractions;

Expand All @@ -14,9 +16,12 @@ public InheritanceInMemoryTest(InheritanceInMemoryFixture fixture, ITestOutputHe
//TestLoggerFactory.TestOutputHelper = testOutputHelper;
}

[ConditionalFact(Skip = "See issue#16963 Cannot compose when using client method in defining query")] // Defining query
public override void Can_query_all_animal_views()
{
Assert.Equal(
CoreStrings.TranslationFailed("OrderBy<AnimalQuery, int>( source: Select<Bird, AnimalQuery>( source: DbSet<Bird>, selector: (b) => MaterializeView(b)), keySelector: (a) => a.CountryId)"),
Assert.Throws<InvalidOperationException>(() => base.Can_query_all_animal_views())
.Message.Replace("\r", "").Replace("\n", ""));
}

protected override bool EnforcesFkConstraints => false;
Expand Down

0 comments on commit 1d9edf1

Please sign in to comment.