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 7fa278c commit ac13adf
Show file tree
Hide file tree
Showing 23 changed files with 70 additions and 24 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 @@ -352,7 +352,7 @@ await AssertQuery<Customer>(
AssertSql(
@"SELECT c
FROM root c
WHERE ((c[""Discriminator""] = ""Customer"") AND ((c[""Region""] ?? ""SP"") = ""BC""))");
WHERE ((c[""Discriminator""] = ""Customer"") AND (((c[""Region""] != null) ? c[""Region""] : ""SP"") = ""BC""))");
}

public override async Task Where_simple(bool isAsync)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2015,13 +2015,13 @@ 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);

AssertSql(
@"SELECT c
@"SELECT c[""CustomerID""], c[""CompanyName""], ((c[""Region""] != null) ? c[""Region""] : ""ZZ"") AS Region
FROM root c
WHERE (c[""Discriminator""] = ""Customer"")");
}
Expand All @@ -2033,7 +2033,7 @@ public override async Task Filter_coalesce_operator(bool isAsync)
AssertSql(
@"SELECT c
FROM root c
WHERE ((c[""Discriminator""] = ""Customer"") AND ((c[""CompanyName""] ?? c[""ContactName""]) = ""The Big Cheese""))");
WHERE ((c[""Discriminator""] = ""Customer"") AND (((c[""CompanyName""] != null) ? c[""CompanyName""] : c[""ContactName""]) = ""The Big Cheese""))");
}

[ConditionalTheory(Skip = "Issue #14935")]
Expand Down Expand Up @@ -3996,6 +3996,12 @@ public override Task Where_string_concat_method_comparison(bool isAsync)
return base.Where_string_concat_method_comparison(isAsync);
}

[ConditionalTheory(Skip = "Issue #14935")]
public override Task Inner_parameter_in_nested_lambdas_gets_preserved(bool isAsync)
{
return base.Inner_parameter_in_nested_lambdas_gets_preserved(isAsync);
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -895,9 +895,8 @@ public virtual Task Project_single_element_from_collection_with_multiple_OrderBy
.FirstOrDefault()));
}

// issue #12597
//[ConditionalTheory]
//[MemberData(nameof(IsAsyncData))]
[ConditionalTheory(Skip = "Issue#12597")]
[MemberData(nameof(IsAsyncData))]
public virtual Task
Project_single_element_from_collection_with_multiple_OrderBys_Take_and_FirstOrDefault_followed_by_projection_of_length_property(
bool 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 ac13adf

Please sign in to comment.