diff --git a/src/EFCore.Relational.Specification.Tests/Query/GearsOfWarQueryRelationalFixture.cs b/src/EFCore.Relational.Specification.Tests/Query/GearsOfWarQueryRelationalFixture.cs
index afdb01d930c..f0566c3696a 100644
--- a/src/EFCore.Relational.Specification.Tests/Query/GearsOfWarQueryRelationalFixture.cs
+++ b/src/EFCore.Relational.Specification.Tests/Query/GearsOfWarQueryRelationalFixture.cs
@@ -14,7 +14,7 @@ public abstract class GearsOfWarQueryRelationalFixture : GearsOfWarQueryFixtureB
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> base.AddOptions(builder).ConfigureWarnings(
- c => c
- .Log(RelationalEventId.QueryClientEvaluationWarning));
+ c => c.Log(RelationalEventId.QueryClientEvaluationWarning)
+ .Log(RelationalEventId.ValueConversionSqlLiteralWarning));
}
}
diff --git a/src/EFCore.Relational.Specification.Tests/Query/NorthwindQueryRelationalFixture.cs b/src/EFCore.Relational.Specification.Tests/Query/NorthwindQueryRelationalFixture.cs
index 64f50e4b0b7..a71a32dd7d7 100644
--- a/src/EFCore.Relational.Specification.Tests/Query/NorthwindQueryRelationalFixture.cs
+++ b/src/EFCore.Relational.Specification.Tests/Query/NorthwindQueryRelationalFixture.cs
@@ -22,7 +22,8 @@ public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder build
c => c
.Log(RelationalEventId.QueryClientEvaluationWarning)
.Log(RelationalEventId.QueryPossibleUnintendedUseOfEqualsWarning)
- .Log(RelationalEventId.QueryPossibleExceptionWithAggregateOperator));
+ .Log(RelationalEventId.QueryPossibleExceptionWithAggregateOperator)
+ .Log(RelationalEventId.ValueConversionSqlLiteralWarning));
protected override Type ContextType => typeof(NorthwindRelationalContext);
}
diff --git a/src/EFCore.Relational/Diagnostics/RelationalEventId.cs b/src/EFCore.Relational/Diagnostics/RelationalEventId.cs
index dec430baa75..12c8ce1bfad 100644
--- a/src/EFCore.Relational/Diagnostics/RelationalEventId.cs
+++ b/src/EFCore.Relational/Diagnostics/RelationalEventId.cs
@@ -64,6 +64,7 @@ private enum Id
QueryClientEvaluationWarning = CoreEventId.RelationalBaseId + 500,
QueryPossibleUnintendedUseOfEqualsWarning,
QueryPossibleExceptionWithAggregateOperator,
+ ValueConversionSqlLiteralWarning,
// Model validation events
ModelValidationKeyDefaultValueWarning = CoreEventId.RelationalBaseId + 600,
@@ -463,6 +464,16 @@ private enum Id
///
public static readonly EventId QueryPossibleExceptionWithAggregateOperator = MakeQueryId(Id.QueryPossibleExceptionWithAggregateOperator);
+ ///
+ ///
+ /// A SQL literal is being generated for a value that is using a value conversion.
+ ///
+ ///
+ /// This event is in the category.
+ ///
+ ///
+ public static readonly EventId ValueConversionSqlLiteralWarning = MakeQueryId(Id.ValueConversionSqlLiteralWarning);
+
private static readonly string _validationPrefix = DbLoggerCategory.Model.Validation.Name + ".";
private static EventId MakeValidationId(Id id) => new EventId((int)id, _validationPrefix + id);
diff --git a/src/EFCore.Relational/Internal/RelationalLoggerExtensions.cs b/src/EFCore.Relational/Internal/RelationalLoggerExtensions.cs
index 1ba7586f60d..e965821b0b0 100644
--- a/src/EFCore.Relational/Internal/RelationalLoggerExtensions.cs
+++ b/src/EFCore.Relational/Internal/RelationalLoggerExtensions.cs
@@ -17,6 +17,7 @@
using Microsoft.EntityFrameworkCore.Migrations.Internal;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Microsoft.EntityFrameworkCore.Update;
using Remotion.Linq;
@@ -1252,6 +1253,46 @@ public static void QueryPossibleExceptionWithAggregateOperator(
}
}
+
+ ///
+ /// This API supports the Entity Framework Core infrastructure and is not intended to be used
+ /// directly from your code. This API may change or be removed in future releases.
+ ///
+ public static void ValueConversionSqlLiteralWarning(
+ [NotNull] this IDiagnosticsLogger diagnostics,
+ [NotNull] Type mappingClrType,
+ [NotNull] ValueConverter valueConverter)
+ {
+ var definition = RelationalStrings.LogValueConversionSqlLiteralWarning;
+
+ var warningBehavior = definition.GetLogBehavior(diagnostics);
+ if (warningBehavior != WarningBehavior.Ignore)
+ {
+ definition.Log(diagnostics,
+ warningBehavior,
+ mappingClrType.ShortDisplayName(),
+ valueConverter.GetType().ShortDisplayName());
+ }
+
+ if (diagnostics.DiagnosticSource.IsEnabled(definition.EventId.Name))
+ {
+ diagnostics.DiagnosticSource.Write(
+ definition.EventId.Name,
+ new ValueConverterEventData(
+ definition,
+ ValueConversionSqlLiteral,
+ mappingClrType,
+ valueConverter));
+ }
+ }
+
+ private static string ValueConversionSqlLiteral(EventDefinitionBase definition, EventData payload)
+ {
+ var d = (EventDefinition