diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerDateTimeFromPartsFunctionTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerDateTimeFromPartsFunctionTranslator.cs index d8d673cd7ee..3bf04def19c 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerDateTimeFromPartsFunctionTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerDateTimeFromPartsFunctionTranslator.cs @@ -5,20 +5,28 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; +using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; +using Microsoft.EntityFrameworkCore.Storage; namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal { public class SqlServerDateTimeFromPartsFunctionTranslator : IMethodCallTranslator { private readonly ISqlExpressionFactory _sqlExpressionFactory; + private readonly IRelationalTypeMappingSource _typeMappingSource; private static readonly MethodInfo _methodInfo = typeof(SqlServerDbFunctionsExtensions) .GetRuntimeMethod(nameof(SqlServerDbFunctionsExtensions.DateTimeFromParts), new[] { typeof(DbFunctions), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int) }); - public SqlServerDateTimeFromPartsFunctionTranslator(ISqlExpressionFactory sqlExpressionFactory) - => _sqlExpressionFactory = sqlExpressionFactory; + public SqlServerDateTimeFromPartsFunctionTranslator( + [NotNull] ISqlExpressionFactory sqlExpressionFactory, + [NotNull] IRelationalTypeMappingSource typeMappingSource) + { + _sqlExpressionFactory = sqlExpressionFactory; + _typeMappingSource = typeMappingSource; + } public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) { @@ -27,7 +35,7 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method "DATETIMEFROMPARTS", arguments.Skip(1), _methodInfo.ReturnType, - _sqlExpressionFactory.FindMapping(typeof(DateTime))) + _typeMappingSource.FindMapping(typeof(DateTime))) : null; } } diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerMethodCallTranslatorProvider.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerMethodCallTranslatorProvider.cs index 6fcfdb1209c..437c6432549 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerMethodCallTranslatorProvider.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerMethodCallTranslatorProvider.cs @@ -3,22 +3,23 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Query; +using Microsoft.EntityFrameworkCore.Storage; namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal { public class SqlServerMethodCallTranslatorProvider : RelationalMethodCallTranslatorProvider { - public SqlServerMethodCallTranslatorProvider([NotNull] RelationalMethodCallTranslatorProviderDependencies dependencies) + public SqlServerMethodCallTranslatorProvider([NotNull] RelationalMethodCallTranslatorProviderDependencies dependencies, [NotNull] IRelationalTypeMappingSource typeMappingSource) : base(dependencies) { var sqlExpressionFactory = dependencies.SqlExpressionFactory; AddTranslators( new IMethodCallTranslator[] { - new SqlServerByteArrayMethodTranslator(sqlExpressionFactory), - new SqlServerConvertTranslator(sqlExpressionFactory), + new SqlServerByteArrayMethodTranslator(sqlExpressionFactory), + new SqlServerConvertTranslator(sqlExpressionFactory), new SqlServerDateDiffFunctionsTranslator(sqlExpressionFactory), - new SqlServerDateTimeFromPartsFunctionTranslator(sqlExpressionFactory), + new SqlServerDateTimeFromPartsFunctionTranslator(sqlExpressionFactory, typeMappingSource), new SqlServerDateTimeMethodTranslator(sqlExpressionFactory), new SqlServerFullTextSearchFunctionsTranslator(sqlExpressionFactory), new SqlServerIsDateFunctionTranslator(sqlExpressionFactory),