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: Throw better exception message when composing after client projection #17499

Merged
merged 1 commit into from
Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,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 @@ -79,7 +79,9 @@ protected override Expression VisitMember(MemberExpression memberExpression)
return BindProperty(innerExpression, memberExpression.Member.GetSimpleMemberName(), memberExpression.Type);
}

return memberExpression.Update(innerExpression);
return TranslationFailed(memberExpression.Expression, innerExpression)
? null
: memberExpression.Update(innerExpression);
}

private Expression BindProperty(Expression source, string propertyName, Type type)
Expand Down Expand Up @@ -110,7 +112,7 @@ private Expression BindProperty(Expression source, string propertyName, Type typ
}
}

var result = BindProperty(entityProjection, entityType.FindProperty(propertyName));
var result = entityProjection.BindProperty(entityType.FindProperty(propertyName));
return result.Type == type
? result
: Expression.Convert(result, type);
Expand All @@ -119,11 +121,6 @@ private Expression BindProperty(Expression source, string propertyName, Type typ
throw new InvalidOperationException(CoreStrings.TranslationFailed(source.Print()));
}

private Expression BindProperty(EntityProjectionExpression entityProjectionExpression, IProperty property)
{
return entityProjectionExpression.BindProperty(property);
}

protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression)
{
// EF.Property case
Expand Down Expand Up @@ -268,8 +265,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 @@ -548,8 +548,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 Down Expand Up @@ -79,10 +81,13 @@ public override void Can_use_of_type_rose()
{
}

[ConditionalFact(Skip = "See issue#13857")]
[ConditionalFact(Skip = "Issue #16963")]
public override void Can_query_all_animal_views()
{
base.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