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 Sep 3, 2019
1 parent fb70477 commit 3fc3cb4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
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

0 comments on commit 3fc3cb4

Please sign in to comment.