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

Continuation of exception message review #22392

Merged
merged 2 commits into from
Sep 3, 2020
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 @@ -188,7 +188,8 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression)
if ((binaryExpression.NodeType == ExpressionType.Equal
|| binaryExpression.NodeType == ExpressionType.NotEqual)
// Visited expression could be null, We need to pass MemberInitExpression
&& TryRewriteEntityEquality(binaryExpression.NodeType, visitedLeft ?? left, visitedRight ?? right, out var result))
&& TryRewriteEntityEquality(
binaryExpression.NodeType, visitedLeft ?? left, visitedRight ?? right, equalsMethod: false, out var result))
{
return result;
}
Expand Down Expand Up @@ -394,6 +395,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
ExpressionType.Equal,
left ?? methodCallExpression.Object,
right ?? methodCallExpression.Arguments[0],
equalsMethod: true,
out var result))
{
return result;
Expand Down Expand Up @@ -421,6 +423,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
ExpressionType.Equal,
left ?? methodCallExpression.Arguments[0],
right ?? methodCallExpression.Arguments[1],
equalsMethod: true,
out var result))
{
return result;
Expand Down Expand Up @@ -720,13 +723,14 @@ private bool TryRewriteContainsEntity(Expression source, Expression item, out Ex
var primaryKeyProperties = entityType.FindPrimaryKey()?.Properties;
if (primaryKeyProperties == null)
{
throw new InvalidOperationException(CoreStrings.EntityEqualityOnKeylessEntityNotSupported(entityType.DisplayName()));
throw new InvalidOperationException(CoreStrings.EntityEqualityOnKeylessEntityNotSupported(
nameof(Queryable.Contains), entityType.DisplayName()));
}

if (primaryKeyProperties.Count > 1)
{
throw new InvalidOperationException(
CoreStrings.EntityEqualityContainsWithCompositeKeyNotSupported(entityType.DisplayName()));
CoreStrings.EntityEqualityOnCompositeKeyEntitySubqueryNotSupported(nameof(Queryable.Contains), entityType.DisplayName()));
}

var property = primaryKeyProperties[0];
Expand Down Expand Up @@ -777,7 +781,7 @@ when sqlParameterExpression.Name.StartsWith(QueryCompilationContext.QueryParamet
return true;
}

private bool TryRewriteEntityEquality(ExpressionType nodeType, Expression left, Expression right, out Expression result)
private bool TryRewriteEntityEquality(ExpressionType nodeType, Expression left, Expression right, bool equalsMethod, out Expression result)
{
var leftEntityReference = left as EntityReferenceExpression;
var rightEntityReference = right as EntityReferenceExpression;
Expand All @@ -797,7 +801,11 @@ private bool TryRewriteEntityEquality(ExpressionType nodeType, Expression left,
var primaryKeyProperties1 = entityType1.FindPrimaryKey()?.Properties;
if (primaryKeyProperties1 == null)
{
throw new InvalidOperationException(CoreStrings.EntityEqualityOnKeylessEntityNotSupported(entityType1.DisplayName()));
throw new InvalidOperationException(CoreStrings.EntityEqualityOnKeylessEntityNotSupported(
nodeType == ExpressionType.Equal
? equalsMethod ? nameof(object.Equals) : "=="
: equalsMethod ? "!" + nameof(object.Equals) : "!=",
entityType1.DisplayName()));
}

result = Visit(
Expand Down Expand Up @@ -828,7 +836,11 @@ private bool TryRewriteEntityEquality(ExpressionType nodeType, Expression left,
var primaryKeyProperties = entityType.FindPrimaryKey()?.Properties;
if (primaryKeyProperties == null)
{
throw new InvalidOperationException(CoreStrings.EntityEqualityOnKeylessEntityNotSupported(entityType.DisplayName()));
throw new InvalidOperationException(CoreStrings.EntityEqualityOnKeylessEntityNotSupported(
nodeType == ExpressionType.Equal
? equalsMethod ? nameof(object.Equals) : "=="
: equalsMethod ? "!" + nameof(object.Equals) : "!=",
entityType.DisplayName()));
}

result = Visit(
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Design/Properties/DesignStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/EFCore.Design/Properties/DesignStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ Change your target project to the migrations project by using the Package Manage
<value>Using design-time services from assembly '{referencedAssembly}'.</value>
</data>
<data name="VersionMismatch" xml:space="preserve">
<value>The EF Core tools version '{toolsVersion}' is older than that of the runtime '{runtimeVersion}'. Update the tools for the latest features and bug fixes.</value>
<value>The Entity Framework tools version '{toolsVersion}' is older than that of the runtime '{runtimeVersion}'. Update the tools for the latest features and bug fixes.</value>
</data>
<data name="WritingMigration" xml:space="preserve">
<value>Writing migration to '{file}'.</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression)
|| binaryExpression.NodeType == ExpressionType.NotEqual)
// Visited expression could be null, We need to pass MemberInitExpression
&& TryRewriteEntityEquality(
binaryExpression.NodeType, newLeft ?? binaryExpression.Left, newRight ?? binaryExpression.Right, out var result))
binaryExpression.NodeType,
newLeft ?? binaryExpression.Left,
newRight ?? binaryExpression.Right,
equalsMethod: false,
out var result))
{
return result;
}
Expand Down Expand Up @@ -710,6 +714,7 @@ static Expression RemapLambda(GroupingElementExpression groupingElement, LambdaE
ExpressionType.Equal,
left ?? methodCallExpression.Object,
right ?? methodCallExpression.Arguments[0],
equalsMethod: true,
out var result))
{
return result;
Expand Down Expand Up @@ -743,6 +748,7 @@ static Expression RemapLambda(GroupingElementExpression groupingElement, LambdaE
ExpressionType.Equal,
left ?? methodCallExpression.Arguments[0],
right ?? methodCallExpression.Arguments[1],
equalsMethod: true,
out var result))
{
return result;
Expand Down Expand Up @@ -1202,13 +1208,14 @@ private bool TryRewriteContainsEntity(Expression source, Expression item, out Ex
var primaryKeyProperties = entityType.FindPrimaryKey()?.Properties;
if (primaryKeyProperties == null)
{
throw new InvalidOperationException(CoreStrings.EntityEqualityOnKeylessEntityNotSupported(entityType.DisplayName()));
throw new InvalidOperationException(CoreStrings.EntityEqualityOnKeylessEntityNotSupported(
nameof(Queryable.Contains), entityType.DisplayName()));
}

if (primaryKeyProperties.Count > 1)
{
throw new InvalidOperationException(
CoreStrings.EntityEqualityContainsWithCompositeKeyNotSupported(entityType.DisplayName()));
CoreStrings.EntityEqualityOnCompositeKeyEntitySubqueryNotSupported(nameof(Queryable.Contains), entityType.DisplayName()));
}

var property = primaryKeyProperties[0];
Expand Down Expand Up @@ -1261,7 +1268,7 @@ when methodCallExpression.Method.IsGenericMethod
return true;
}

private bool TryRewriteEntityEquality(ExpressionType nodeType, Expression left, Expression right, out Expression result)
private bool TryRewriteEntityEquality(ExpressionType nodeType, Expression left, Expression right, bool equalsMethod, out Expression result)
{
var leftEntityReference = left as EntityReferenceExpression;
var rightEntityReference = right as EntityReferenceExpression;
Expand All @@ -1281,7 +1288,11 @@ private bool TryRewriteEntityEquality(ExpressionType nodeType, Expression left,
var primaryKeyProperties1 = entityType1.FindPrimaryKey()?.Properties;
if (primaryKeyProperties1 == null)
{
throw new InvalidOperationException(CoreStrings.EntityEqualityOnKeylessEntityNotSupported(entityType1.DisplayName()));
throw new InvalidOperationException(CoreStrings.EntityEqualityOnKeylessEntityNotSupported(
nodeType == ExpressionType.Equal
? equalsMethod ? nameof(object.Equals) : "=="
: equalsMethod ? "!" + nameof(object.Equals) : "!=",
entityType1.DisplayName()));
}

result = Visit(
Expand Down Expand Up @@ -1312,15 +1323,22 @@ private bool TryRewriteEntityEquality(ExpressionType nodeType, Expression left,
var primaryKeyProperties = entityType.FindPrimaryKey()?.Properties;
if (primaryKeyProperties == null)
{
throw new InvalidOperationException(CoreStrings.EntityEqualityOnKeylessEntityNotSupported(entityType.DisplayName()));
throw new InvalidOperationException(CoreStrings.EntityEqualityOnKeylessEntityNotSupported(
nodeType == ExpressionType.Equal
? equalsMethod ? nameof(object.Equals) : "=="
: equalsMethod ? "!" + nameof(object.Equals) : "!=",
entityType.DisplayName()));
}

if (primaryKeyProperties.Count > 1
&& (leftEntityReference?.SubqueryEntity != null
|| rightEntityReference?.SubqueryEntity != null))
{
throw new InvalidOperationException(
CoreStrings.EntityEqualitySubqueryWithCompositeKeyNotSupported(entityType.DisplayName()));
throw new InvalidOperationException(CoreStrings.EntityEqualityOnCompositeKeyEntitySubqueryNotSupported(
nodeType == ExpressionType.Equal
? equalsMethod ? nameof(object.Equals) : "=="
: equalsMethod ? "!" + nameof(object.Equals) : "!=",
entityType.DisplayName()));
}

result = Visit(
Expand Down
46 changes: 42 additions & 4 deletions src/EFCore.Relational/Properties/RelationalStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading