Skip to content

Commit

Permalink
Ignore convert nodes from nullable to non-nullable
Browse files Browse the repository at this point in the history
Fixes #16653
  • Loading branch information
roji committed Jul 18, 2019
1 parent 1c675ca commit 38c79bf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ protected override Expression VisitUnary(UnaryExpression unaryExpression)
// Object convert needs to be converted to explicit cast when mismatching types
if (operand.Type.IsInterface
&& unaryExpression.Type.GetInterfaces().Any(e => e == operand.Type)
|| unaryExpression.Type.UnwrapNullableType() == operand.Type
|| unaryExpression.Type.UnwrapNullableType() == operand.Type.UnwrapNullableType()
|| unaryExpression.Type.UnwrapNullableType() == typeof(Enum))
{
return sqlOperand;
Expand Down
9 changes: 9 additions & 0 deletions test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5989,5 +5989,14 @@ public virtual Task Inner_parameter_in_nested_lambdas_gets_preserved(bool isAsyn
cs => cs.Where(c => c.Orders.Where(o => c == new Customer { CustomerID = o.CustomerID }).Count() > 0),
entryCount: 89);
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Convert_to_nullable_on_nullable_value_is_ignored(bool isAsync)
{
return AssertQuery<Order>(
isAsync,
os => os.Select(o => new Order { OrderDate = o.OrderDate.Value }));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4877,6 +4877,17 @@ FROM [Orders] AS [o]
WHERE (([c].[CustomerID] = [o].[CustomerID]) AND [o].[CustomerID] IS NOT NULL) AND (([c].[CustomerID] = [o].[CustomerID]) AND [o].[CustomerID] IS NOT NULL)) > 0");
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public override async Task Convert_to_nullable_on_nullable_value_is_ignored(bool isAsync)
{
await base.Convert_to_nullable_on_nullable_value_is_ignored(isAsync);

AssertSql(
@"SELECT [o].[OrderDate]
FROM [Orders] AS [o]");
}

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

Expand Down

0 comments on commit 38c79bf

Please sign in to comment.