@@ -36,6 +36,8 @@ public class DefaultQuerySqlGenerator : ThrowingExpressionVisitor, ISqlExpressio
36
36
private ReducingExpressionVisitor _reducingExpressionVisitor ;
37
37
private BooleanExpressionTranslatingVisitor _booleanExpressionTranslatingVisitor ;
38
38
private InExpressionValuesExpandingVisitor _inExpressionValuesExpandingVisitor ;
39
+
40
+ private bool _valueConverterWarningsEnabled ;
39
41
40
42
private static readonly Dictionary < ExpressionType , string > _operatorMap = new Dictionary < ExpressionType , string >
41
43
{
@@ -241,6 +243,10 @@ public virtual Expression VisitSelect(SelectExpression selectExpression)
241
243
_relationalCommandBuilder . Append ( "1" ) ;
242
244
}
243
245
246
+ var oldValueConverterWarningsEnabled = _valueConverterWarningsEnabled ;
247
+
248
+ _valueConverterWarningsEnabled = true ;
249
+
244
250
if ( selectExpression . Tables . Count > 0 )
245
251
{
246
252
_relationalCommandBuilder . AppendLine ( )
@@ -295,6 +301,8 @@ public virtual Expression VisitSelect(SelectExpression selectExpression)
295
301
}
296
302
}
297
303
304
+ _valueConverterWarningsEnabled = oldValueConverterWarningsEnabled ;
305
+
298
306
return selectExpression ;
299
307
}
300
308
@@ -818,6 +826,8 @@ private string GenerateSqlLiteral(object value)
818
826
mapping = Dependencies . TypeMappingSource . GetMappingForValue ( value ) ;
819
827
}
820
828
829
+ LogValueConversionWarning ( mapping ) ;
830
+
821
831
return mapping . GenerateSqlLiteral ( value ) ;
822
832
}
823
833
@@ -919,7 +929,13 @@ public virtual Expression VisitStringCompare(StringCompareExpression stringCompa
919
929
/// </returns>
920
930
public virtual Expression VisitIn ( InExpression inExpression )
921
931
{
922
- GenerateIn ( inExpression , negated : false ) ;
932
+ var oldValueConverterWarningsEnabled = _valueConverterWarningsEnabled ;
933
+
934
+ _valueConverterWarningsEnabled = false ;
935
+
936
+ GenerateIn ( inExpression ) ;
937
+
938
+ _valueConverterWarningsEnabled = oldValueConverterWarningsEnabled ;
923
939
924
940
return inExpression ;
925
941
}
@@ -1175,8 +1191,14 @@ protected override Expression VisitConditional(ConditionalExpression conditional
1175
1191
{
1176
1192
_relationalCommandBuilder . Append ( "WHEN " ) ;
1177
1193
1194
+ var oldValueConverterWarningsEnabled = _valueConverterWarningsEnabled ;
1195
+
1196
+ _valueConverterWarningsEnabled = false ;
1197
+
1178
1198
Visit ( conditionalExpression . Test ) ;
1179
1199
1200
+ _valueConverterWarningsEnabled = oldValueConverterWarningsEnabled ;
1201
+
1180
1202
_relationalCommandBuilder . AppendLine ( ) ;
1181
1203
_relationalCommandBuilder . Append ( "THEN " ) ;
1182
1204
@@ -1248,6 +1270,13 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression)
1248
1270
{
1249
1271
Check . NotNull ( binaryExpression , nameof ( binaryExpression ) ) ;
1250
1272
1273
+ var oldValueConverterWarningsEnabled = _valueConverterWarningsEnabled ;
1274
+
1275
+ _valueConverterWarningsEnabled
1276
+ = _valueConverterWarningsEnabled
1277
+ && binaryExpression . NodeType != ExpressionType . Equal
1278
+ && binaryExpression . NodeType != ExpressionType . NotEqual ;
1279
+
1251
1280
switch ( binaryExpression . NodeType )
1252
1281
{
1253
1282
case ExpressionType . Coalesce :
@@ -1308,6 +1337,8 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression)
1308
1337
break ;
1309
1338
}
1310
1339
1340
+ _valueConverterWarningsEnabled = oldValueConverterWarningsEnabled ;
1341
+
1311
1342
return binaryExpression ;
1312
1343
}
1313
1344
@@ -1556,6 +1587,8 @@ public virtual Expression VisitExplicitCast(ExplicitCastExpression explicitCastE
1556
1587
RelationalStrings . UnsupportedType ( explicitCastExpression . Type . ShortDisplayName ( ) ) ) ;
1557
1588
}
1558
1589
1590
+ LogValueConversionWarning ( typeMapping ) ;
1591
+
1559
1592
_relationalCommandBuilder . Append ( typeMapping . StoreType ) ;
1560
1593
1561
1594
_relationalCommandBuilder . Append ( ")" ) ;
@@ -1652,17 +1685,32 @@ protected override Expression VisitParameter(ParameterExpression parameterExpres
1652
1685
if ( _relationalCommandBuilder . ParameterBuilder . Parameters
1653
1686
. All ( p => p . InvariantName != parameterExpression . Name ) )
1654
1687
{
1688
+ var typeMapping
1689
+ = _typeMapping
1690
+ ?? Dependencies . TypeMappingSource . GetMapping ( parameterExpression . Type ) ;
1691
+
1692
+ LogValueConversionWarning ( typeMapping ) ;
1693
+
1655
1694
_relationalCommandBuilder . AddParameter (
1656
1695
parameterExpression . Name ,
1657
1696
parameterName ,
1658
- _typeMapping ?? Dependencies . TypeMappingSource . GetMapping ( parameterExpression . Type ) ,
1697
+ typeMapping ,
1659
1698
parameterExpression . Type . IsNullableType ( ) ) ;
1660
1699
}
1661
1700
1662
1701
_relationalCommandBuilder . Append ( parameterName ) ;
1663
1702
1664
1703
return parameterExpression ;
1665
1704
}
1705
+
1706
+ private void LogValueConversionWarning ( CoreTypeMapping typeMapping )
1707
+ {
1708
+ if ( _valueConverterWarningsEnabled
1709
+ && typeMapping . Converter != null )
1710
+ {
1711
+ Dependencies . Logger . ValueConversionSqlLiteralWarning ( typeMapping . ClrType , typeMapping . Converter ) ;
1712
+ }
1713
+ }
1666
1714
1667
1715
/// <summary>
1668
1716
/// Visits a PropertyParameterExpression.
0 commit comments