Skip to content

Commit

Permalink
Teeny tiny bugs
Browse files Browse the repository at this point in the history
Part of #16133
Part of #16144
Resolves #16152
Part of #15662
  • Loading branch information
smitpatel committed Jun 21, 2019
1 parent e4f4a44 commit 195faa0
Show file tree
Hide file tree
Showing 21 changed files with 59 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.Query.Pipeline;
using Microsoft.EntityFrameworkCore.Storage;
using Newtonsoft.Json.Linq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.Pipeline;

namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Pipeline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,18 @@ public CosmosSqlTranslatingExpressionVisitor(

public SqlExpression Translate(Expression expression)
{
var translation = (SqlExpression)Visit(expression);
var result = Visit(expression);

translation = _sqlExpressionFactory.ApplyDefaultTypeMapping(translation);
if (result is SqlExpression translation)
{
translation = _sqlExpressionFactory.ApplyDefaultTypeMapping(translation);

_sqlVerifyingExpressionVisitor.Visit(translation);

_sqlVerifyingExpressionVisitor.Visit(translation);
return translation;
}

return translation;
return null;
}

private class SqlTypeMappingVerifyingExpressionVisitor : ExpressionVisitor
Expand Down Expand Up @@ -176,6 +181,14 @@ private static Expression TryRemoveImplicitConvert(Expression expression)

protected override Expression VisitBinary(BinaryExpression binaryExpression)
{
if (binaryExpression.NodeType == ExpressionType.Coalesce)
{
return Visit(Expression.Condition(
Expression.NotEqual(binaryExpression.Left, Expression.Constant(null, binaryExpression.Left.Type)),
binaryExpression.Left,
binaryExpression.Right));
}

var left = TryRemoveImplicitConvert(binaryExpression.Left);
var right = TryRemoveImplicitConvert(binaryExpression.Right);

Expand Down Expand Up @@ -264,6 +277,8 @@ protected override Expression VisitUnary(UnaryExpression unaryExpression)

protected override Expression VisitListInit(ListInitExpression node) => null;

protected override Expression VisitInvocation(InvocationExpression node) => null;

protected override Expression VisitConstant(ConstantExpression constantExpression)
=> new SqlConstantExpression(constantExpression, null);

Expand Down
2 changes: 0 additions & 2 deletions src/EFCore.Cosmos/Query/Pipeline/SelectExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ private int AddToProjection(Expression expression, string alias)
public void ApplyDistinct()
{
IsDistinct = true;

ClearOrdering();
}

public void ClearOrdering()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq.Expressions;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.Query.Pipeline;
using Microsoft.EntityFrameworkCore.Storage;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.Pipeline;

namespace Microsoft.EntityFrameworkCore.InMemory.Query.Pipeline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.Query.Pipeline;
using Microsoft.EntityFrameworkCore.Relational.Query.Pipeline.SqlExpressions;
using Microsoft.EntityFrameworkCore.Storage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.Pipeline;
using Microsoft.EntityFrameworkCore.Storage;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,25 @@ public RelationalSqlTranslatingExpressionVisitor(

public SqlExpression Translate(Expression expression)
{
var translation = (SqlExpression)Visit(expression);
var result = Visit(expression);

if (translation is SqlUnaryExpression sqlUnaryExpression
&& sqlUnaryExpression.OperatorType == ExpressionType.Convert
&& sqlUnaryExpression.Type == typeof(object))
if (result is SqlExpression translation)
{
translation = sqlUnaryExpression.Operand;
}
if (translation is SqlUnaryExpression sqlUnaryExpression
&& sqlUnaryExpression.OperatorType == ExpressionType.Convert
&& sqlUnaryExpression.Type == typeof(object))
{
translation = sqlUnaryExpression.Operand;
}

translation = _sqlExpressionFactory.ApplyDefaultTypeMapping(translation);

translation = _sqlExpressionFactory.ApplyDefaultTypeMapping(translation);
_sqlVerifyingExpressionVisitor.Visit(translation);

_sqlVerifyingExpressionVisitor.Visit(translation);
return translation;
}

return translation;
return null;
}

private class SqlTypeMappingVerifyingExpressionVisitor : ExpressionVisitor
Expand Down Expand Up @@ -253,6 +258,9 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression)
protected override Expression VisitNewArray(NewArrayExpression node) => null;

protected override Expression VisitListInit(ListInitExpression node) => null;

protected override Expression VisitInvocation(InvocationExpression node) => null;

protected override Expression VisitConstant(ConstantExpression constantExpression)
=> new SqlConstantExpression(constantExpression, null);

Expand Down
1 change: 1 addition & 0 deletions src/EFCore/ChangeTracking/Internal/ArrayPropertyValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;

Expand Down
1 change: 1 addition & 0 deletions src/EFCore/ChangeTracking/Internal/IStateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Update;
using Microsoft.Extensions.DependencyInjection;
Expand Down
1 change: 1 addition & 0 deletions src/EFCore/ChangeTracking/Internal/StateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Update;
using Microsoft.Extensions.DependencyInjection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.DependencyInjection;

Expand Down
3 changes: 2 additions & 1 deletion src/EFCore/Metadata/IEntityMaterializerSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
using System;
using System.Linq.Expressions;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.EntityFrameworkCore.Metadata
namespace Microsoft.EntityFrameworkCore.Query
{
/// <summary>
/// <para>
Expand Down
4 changes: 3 additions & 1 deletion src/EFCore/Metadata/Internal/EntityMaterializerSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
using System.Threading;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.EntityFrameworkCore.Metadata.Internal
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
/// <summary>
/// <para>
Expand Down
1 change: 1 addition & 0 deletions src/EFCore/Metadata/PropertyParameterBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq.Expressions;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.Storage;

namespace Microsoft.EntityFrameworkCore.Metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2015,7 +2015,7 @@ FROM root c
WHERE (c[""Discriminator""] = ""Customer"")");
}

[ConditionalTheory(Skip = "Issue#16152")]
[ConditionalTheory]
public override async Task Projection_null_coalesce_operator(bool isAsync)
{
await base.Projection_null_coalesce_operator(isAsync);
Expand Down
2 changes: 2 additions & 0 deletions test/EFCore.Tests/DbContextServicesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.TestUtilities;
using Microsoft.EntityFrameworkCore.ValueGeneration;
using Microsoft.Extensions.Caching.Memory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using System.Linq.Expressions;
using System.Reflection;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.Storage;
using Xunit;

Expand Down
1 change: 1 addition & 0 deletions test/EFCore.Tests/TestUtilities/FakeStateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Update;

Expand Down

0 comments on commit 195faa0

Please sign in to comment.