diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlConvertTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlConvertTranslator.cs index 752e00fd9..b252ad953 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlConvertTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlConvertTranslator.cs @@ -17,20 +17,22 @@ public class NpgsqlConvertTranslator : IMethodCallTranslator { static readonly Dictionary TypeMapping = new Dictionary { - [nameof(Convert.ToBoolean)] = "bool", - [nameof(Convert.ToByte)] = "smallint", - [nameof(Convert.ToDecimal)] = "numeric", - [nameof(Convert.ToDouble)] = "double precision", - [nameof(Convert.ToInt16)] = "smallint", - [nameof(Convert.ToInt32)] = "int", - [nameof(Convert.ToInt64)] = "bigint", - [nameof(Convert.ToString)] = "text" + [nameof(Convert.ToBoolean)] = "bool", + [nameof(Convert.ToByte)] = "smallint", + [nameof(Convert.ToDateTime)] = "timestamp with time zone", + [nameof(Convert.ToDecimal)] = "numeric", + [nameof(Convert.ToDouble)] = "double precision", + [nameof(Convert.ToInt16)] = "smallint", + [nameof(Convert.ToInt32)] = "int", + [nameof(Convert.ToInt64)] = "bigint", + [nameof(Convert.ToString)] = "text" }; static readonly List SupportedTypes = new List { typeof(bool), typeof(byte), + typeof(DateTime), typeof(decimal), typeof(double), typeof(float), diff --git a/test/EFCore.PG.FunctionalTests/Query/NorthwindFunctionsQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/NorthwindFunctionsQueryNpgsqlTest.cs index 11d982ad7..18ba64bfb 100644 --- a/test/EFCore.PG.FunctionalTests/Query/NorthwindFunctionsQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/NorthwindFunctionsQueryNpgsqlTest.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; @@ -41,6 +41,18 @@ public override Task Where_math_log_new_base(bool async) public override Task Convert_ToString(bool async) => base.Convert_ToString(async); + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Convert_ToDateTime(bool async) + { + await AssertQuery( + async, + ss => ss.Set().Where(o => o.OrderDate == Convert.ToDateTime(o.OrderDate.ToString())), + entryCount: 830); + + AssertContainsSqlFragment(@"WHERE (o.""OrderDate"" = CAST(CAST(o.""OrderDate"" AS text) AS timestamp without time zone)) OR (o.""OrderDate"" IS NULL)"); + } + #region Substring [ConditionalTheory]