Skip to content

Commit

Permalink
Fix to #7364 - Query : ToString() method that takes a formatter argum…
Browse files Browse the repository at this point in the history
…ent should still be translated on the client

Fix is to only translate ToString calls that have no arguments. Ones with the arguments will be evaluated on the client.
  • Loading branch information
maumar committed Jan 11, 2017
1 parent 133daaa commit 8b0ef7f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore.Infrastructure;
Expand Down Expand Up @@ -6437,6 +6438,24 @@ public virtual void Select_expression_int_to_string()
}));
}

[ConditionalFact]
public virtual void ToString_with_formatter_is_evaluated_on_the_client()
{
AssertQuery<Order>(
os => os.Where(o => o.OrderDate != null)
.Select(o => new Order
{
ShipName = o.OrderID.ToString("X")
}));

AssertQuery<Order>(
os => os.Where(o => o.OrderDate != null)
.Select(o => new Order
{
ShipName = o.OrderID.ToString(new CultureInfo("en-US"))
}));
}

[ConditionalFact]
public virtual void Select_expression_date_add_year()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
using Microsoft.EntityFrameworkCore.Query.Expressions;

namespace Microsoft.EntityFrameworkCore.Query.ExpressionTranslators.Internal
Expand Down Expand Up @@ -48,6 +49,7 @@ public virtual Expression Translate(MethodCallExpression methodCallExpression)
string storeType;

if (methodCallExpression.Method.Name == nameof(ToString)
&& methodCallExpression.Arguments.Count == 0
&& methodCallExpression.Object != null
&& _typeMapping.TryGetValue(
methodCallExpression.Object.Type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6368,6 +6368,21 @@ FROM [Orders] AS [o]
Sql);
}

public override void ToString_with_formatter_is_evaluated_on_the_client()
{
base.ToString_with_formatter_is_evaluated_on_the_client();

Assert.Equal(
@"SELECT [o].[OrderID]
FROM [Orders] AS [o]
WHERE [o].[OrderDate] IS NOT NULL
SELECT [o].[OrderID]
FROM [Orders] AS [o]
WHERE [o].[OrderDate] IS NOT NULL",
Sql);
}

public override void Select_expression_other_to_string()
{
base.Select_expression_other_to_string();
Expand Down

0 comments on commit 8b0ef7f

Please sign in to comment.