forked from dotnet/efcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Translators): support for translating ToString() to sql server
Fixes dotnet#6264
- Loading branch information
1 parent
4b60abb
commit ea3f5e3
Showing
5 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...kCore.SqlServer/Query/ExpressionTranslators/Internal/SqlServerObjectToStringTranslator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
namespace Microsoft.EntityFrameworkCore.Query.ExpressionTranslators.Internal | ||
{ | ||
using System; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using Microsoft.EntityFrameworkCore.Query.Expressions; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <seealso cref="Microsoft.EntityFrameworkCore.Query.ExpressionTranslators.IMethodCallTranslator" /> | ||
public class SqlServerObjectToStringTranslator : IMethodCallTranslator | ||
{ | ||
/// <summary> | ||
/// Translates the given method call expression. | ||
/// </summary> | ||
/// <param name="methodCallExpression">The method call expression.</param> | ||
/// <returns> | ||
/// A SQL expression representing the translated MethodCallExpression. | ||
/// </returns> | ||
public virtual Expression Translate(MethodCallExpression methodCallExpression) | ||
{ | ||
if (methodCallExpression.Method.Name == nameof(ToString)) | ||
{ | ||
return new SqlFunctionExpression( | ||
functionName: "CONVERT", | ||
returnType: methodCallExpression.Type, | ||
arguments: new[] | ||
{ | ||
new SqlFragmentExpression("VARCHAR(MAX)"), | ||
methodCallExpression.Object | ||
}); | ||
} | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters